When dealing with jQuery selectors, scenarios arise where you need to select a set of elements while excluding others. In this case, selecting all checkboxes present on a web page, but not a particular one, can be achieved with a few lines of jQuery code.
Given a markup consisting of a table with several input checkboxes, with one checkbox having a unique ID of "select_all," the objective is to select all checkboxes except the "#select_all" checkbox when it is clicked.
jQuery Code:
To accomplish this, you can utilize the following jQuery code:
$('#select_all').change(function() { var checkboxes = $(this).closest('form').find(':checkbox'); checkboxes.prop('checked', $(this).is(':checked')); });
Explanation:
This approach effectively toggles the checked state of all checkboxes when the "select_all" checkbox is clicked.
以上がjQueryで特定のチェックボックスを除くすべてのチェックボックスを選択するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。