SoFunction
Updated on 2025-04-10

Jquery Select all and unselect instance code

This article will share with you a code based on jQuery's selection, anti-select and non-select functions, which is suitable for scenarios where multiple selections of web pages require batch operations (such as batch deletion, etc.). The article combines examples, the code is concise, and basically covers all aspects of the option selection operation. I hope it can help WEB enthusiasts in need.

//Select all

 $('#checkAll').click(function () {
  //Judge whether it is selected  var bischecked = $('#checkAll').is(':checked');
  var fruit = $('input[name="check"]');
  bischecked ? ('checked', true) : ('checked', false);
 });

//Reselect   traversal checkbox If it is currently selected, set to Uncheck, otherwise the same

 $("#tabVouchList tr").each(function () {
  if ($("td:eq(0) input[name='check']", $(this)).is(':checked')) {
   $(this).attr('checked', false);
  } else {
   $(this).attr('checked', true);
  }
 });

 HTML table

<table >
 <tr>
  <th>
   <input type="checkbox" name="checkAll" />
  </th>
  <th>
   Line number
  </th>
  <th>
   name
  </th>
 </tr>
 <tr>
  <td>
   <input type="checkbox" name="check" />
  </td>
  <td>
   Line number
  </td>
  <td>
   name
  </td>
 </tr>
</table>

The above code is all the code that jquery implements all the selection without selecting anything. Is the code very simple? I hope it will be helpful to everyone's work and study.