我試圖通過單擊表頭中的一個複選框來檢查/取消選中所有複選框。首先點擊添加屬性輸入,其次取消選中。它只工作一次。在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