jQuery implements a pair of checkboxes to select and uncheck

  • 2020-05-10 17:39:25
  • OfStack

This article demonstrates how jQuery implements pair selection and corresponding cancellation of check boxes. Share with you for your reference. The specific implementation method is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Implementation of a pair of check box selection, corresponding to the cancel function </title>
<script type="text/javascript" src="/js/jquery-1.6.2.min.js"></script>
<script>
$(function(){
 var classA = $(".classA");
 classA.change(function(){
  classA.attr("checked",Boolean($(this).attr("checked")));
 })
 var classB = $(".classB");
 classB.change(function(){
  classB.attr("checked",Boolean($(this).attr("checked")));
 })
})
</script>
</head>
<body>
<p>A group </p>
<input type="checkbox" class="classA">
<input type="checkbox" class="classA">
<p>B group </p>
<input type="checkbox" class="classB">
<input type="checkbox" class="classB">
</body>
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: