我试图通过单击表头中的一个复选框来检查/取消选中所有复选框。首先点击添加属性输入,其次取消选中。它只工作一次。在Firefox和Chrome上进行测试。 Аttributes不断变化,但这不会显示在页面中。我只在浏览器调试器中看到它。检查并取消选中输入只能用Jquery工作一次
<table>
<thead>
<tr>
<th><input type="checkbox" /></th>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" /></td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td>2</td>
</tr>
<tr>
<td><input type="checkbox" /></td>
<td>3</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(function() {
$('th input[type="checkbox"]').click(function(){
if ($(this).is(':checked'))
$('td input[type="checkbox"]').attr('checked', 'checked');
else
// $('td input[type="checkbox"]').attr('checked', false);
$('td input[type="checkbox"]').removeAttr('checked');
})
});
</script>
它的工作原理!谢谢! – glutaminefree
@АндрейН。别客气。 – Musa
它的工作原理,谢谢!但attr()每次都工作......为什么不现在呢? – brandelizer