すべてのチェックボックスをチェックしたり、チェックを外したりしようとしています。最初に、属性を入力に追加するをクリックし、2番目のチェックを外します。それは一度だけ動作します。 FirefoxとChromeでのテスト。 Аribributesは変更を続けますが、ページには表示されません。私はブラウザのデバッガでしか見ません。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>
サンプル http://jsfiddle.net/aJhm9/
- :その後、次のコードを使用します!ありがとう! – glutaminefree
@АндрейН。どういたしまして。 – Musa
それは、ありがとう! attr()は毎回働いていましたが、今はなぜですか? – brandelizer