2016-12-27 59 views
-2

这里举选择框用的是我的外接排功能如何添加行

$(document).ready(function() { 
    $(".kg").blur(function() 
    { 
    if($(".kg:last").val() > 0) 
    { 
     $("#one").clone(true).appendTo("#mainDiv") 
     .find('input[type="text"]').val('').end() 
     .find('select[option=""]').val(''); 
     var rowCount = $('#mainDiv tr').length; 
     $(".srNo:last").val(rowCount); 
    } 
    }); 
}); 

这里我使用boostrop使用此功能选择:

function add(thisObj) 
{ 
    var row = $(thisObj).parents('.itemRow'); 
    row.find.fn.select2.defaults.set("theme", "bootstrap"); 
    row.find(".hey").select2({ 
      width: null 
    }); 
} 

这是我与我的添加行代码函数我想申请选择搜索在每一行如何有可能我不能够在每一行使用

+0

你能请提供的jsfiddle链接? –

+0

https://jsfiddle.net/wcm2o1tr/1/ –

+0

@ I'mBack https://jsfiddle.net/wcm2o1tr/1/ –

回答

0

刚刚更新了答案,我想你试图操纵事件本身。

单击事件时,第一个对象是Event而不是当前目标。 只需使用.currentTarget即可访问它们。

得到siblings(所有元素在相同的级别)。

为了滤除你使用filter功能就像:

var elements_filters = $(element).siblings().filter('.class') //filter([selector]) 

可以使用父元素上append函数为儿童的父节点上添加其他元素;

参见下面的例子(请在框中单击):

var add = function (obj){ 
 
    var filtered = $(obj.currentTarget).children().filter('.red') 
 
console.log(filtered); 
 
$('div').html(filtered); 
 
    
 
} 
 

 
$("body").on("click", "tr", add);
.red{ 
 
    background-color:red 
 
} 
 

 
table{ 
 
    border: 1px solid black; 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<table> 
 
    <tr class="line"> 
 
    <td class="red">Test</td> 
 
    <td>Test</td> 
 
    <td>Test</td> 
 
    <td>Test</td> 
 
    </tr> 
 
</table> 
 
<br/> 
 
response: 
 
<div> 
 
    </div>

+0

不工作。 ... –

+0

只是更新答案...如果你想要的实际代码...你必须发布的HTML片段。 @PrashantBhatt –

+0

function add(thisObj) var elements_filters = $(thisObj).siblings()。filter('。colorId') row.find.fn.select2.defaults.set(“theme”,“bootstrap” ); row.find(“。colorId”)。select2({width:null }); } –