【发布时间】:2010-03-30 17:54:06
【问题描述】:
我对 each() 和 .each() 感到困惑......我想我需要同时使用这两个,但我不确定如何......
基本上,我有一系列复选框,当它们被选中时,我想获取最近的表格行的 id 并将其添加到一个数组中,然后我可以序列化并传递给一个函数。
所以,html 看起来像这样:
<tr id="t1"><td><input type="checkbox" name="did[]" value="232" class="bd" /></td></tr>
<tr id="t2"><td><input type="checkbox" name="did[]" value="234" class="bd" /></td></tr>
<tr id="t3"><td><input type="checkbox" name="did[]" value="676" class="bd" /></td></tr>
<tr><td><button id="tsid" name="tsid" type="button">Send</button></td></tr>
并且,当(如果)复选框被选中时,我想获取最接近的 tr id 并将其存储在数组中:
var trids = []
然后序列化输入数据和trids数组...
到目前为止,我只有这个:
$('#tsid').click(function() {
//meant to get the values of the selected checkboxes
var myData = $('input[name=did[]]').serialize();
//meant to find and store the closest tr ids in an array...
$('.bd').each(function() {
var trids = $(this).closest("tr").get(0); //and now I'm lost...
});
}
【问题讨论】: