| 以下为引用的内容: $("#s1 input[@type=checkbox]").each(function(i){
if($("#s1 input[@type=checkbox]:eq('"+i+"')").attr("checked") == true) { alert(i); //---------------1 $("#s1 tr:eq('"+(i+1)+"')").remove();//-----------2 } }) 如果把2注释掉就会就会正确输出i, 如果不注释掉2,就总是remove 1个 |
问题分析
| 以下为引用的内容: <tr ID=1><td>checkbox1<td></tr>
<tr ID=2><td>checkbox2<td></tr> <tr ID=3><td>checkbox3<td></tr> <tr ID-4><td>checkbox4<td></tr> i=0 的时候 ID=1 移除 移除后代码 <tr ID=2><td>checkbox2<td></tr> <tr ID=3><td>checkbox3<td></tr> <tr ID-4><td>checkbox4<td></tr> i=1的时候 此时 ID=2 的序号是0 ID=3的序号是 1 此时移除 <tr ID=3><td>checkbox3<td></tr> 移除后代码 <tr ID=2><td>checkbox2<td></tr> <tr ID-4><td>checkbox4<td></tr> i=2的时候 此时 tr长度只有2 所以就没有可移除对象了 |
所以正确代码应该是
| 以下为引用的内容: $("#s1 input[@type=checkbox]:checked").each(function(i){ $(this).parent().parent().remove(); }) |
声明:本站教程文章版权为一起Ext(http://www.17ext.com/)所有,转载请注明出处