我是Jquery的新手,即使在搜索doc和这里(stackoverflow)后,找不到解决方法。Jquery在过滤后检查元素
下面是我的下表,其中有3行,每行都有一个复选框(行中的第一个元素)。
现在有filtermatch="false" style="display: none;",
的行将被隐藏。
我也有一个按钮来检查所有并取消全部选中。如果不应用隐藏,它会工作,但如果某个元素被隐藏,则勾选按钮也会隐藏对象被选中/未选中。
我的问题是如何获得第2排,而无需修改表中任何HTML代码进行核对(实际上,通过其他人的脚本自动生成的表,我只是写我的脚本来控制显示。)
HTML
<table id="RankTable" border="0" width="800">
<thead>
<tr>
<th filter="false"><input type="button" id="selectall" value="all"></th>
<th filter="false">rank</th>
<th filter-type="ddl">degree</th>
<th filter-type="ddl">lastposition</th>
<th filter-type="ddl">workingyear</th>
<th>realname</th>
<th>email</th>
<th>mobile</th>
</tr>
</thead>
<tbody>
<tr id="answer-row" style="">
<td><input type="checkbox" name="answers" value="140"> </td>
<td>2 </td>
<td>bachelor </td>
<td>项目经理 </td>
<td>9 </td>
<td> </td>
<td><a href="mailto:[email protected]?subject=Invitation for an interview">[email protected]</a></td>
<td>12316459749816 </td>
</tr>
<tr id="answer-row" style="">
<td><input type="checkbox" name="answers" value="139"> </td>
<td>6 </td>
<td>bachelor </td>
<td>项目主管 </td>
<td>9 </td>
<td> </td>
<td><a href="mailto:[email protected]?subject=Invitation for an interview">[email protected]</a></td>
<td>12345646 </td>
</tr>
<tr id="answer-row" filtermatch="false" style="display: none;">
<td><input type="checkbox" name="answers" value="141"> </td>
<td>7 </td>
<td>master </td>
<td>程序员 </td>
<td>1 </td>
<td> </td>
<td><a href="mailto:[email protected]?subject=Invitation for an interview">test09[email protected]</a></td>
<td>56456161 </td>
</tr>
</tbody>
</table>
js脚本:
$('#selectall').toggle(function() {
$("input[name='answers']").attr("checked", 'true');
$("input[id='selectall']").attr("value", '{% trans "None" %}');
}, function() {
$("input[name='answers']").removeAttr("checked");
$("input[id='selectall']").attr("value", '{% trans "All" %}');
});
提前感谢任何投入。
谢谢大家,我只是自己的身影的解决方案。这里是代码: $('#selectall')。toggle(function(){ $('tr [style =“”]')。find(“input [name ='answers']”)。attr (“checked”,'true'); $(“input [id ='selectall']”)。attr(“value”,'{%trans'None'%}'); },function(){ (“input”[name ='answers']“)。removeAttr(”checked“); $(”input [id ='selectall']“)。 attr(“value”,'{%trans'全部“%}”); }); – user3409626