jQuery实现复选框成对选择及对应取消的方法

 更新时间:2015年03月03日 15:59:44   作者:代码家园  
这篇文章主要介绍了jQuery实现复选框成对选择及对应取消的方法,实例分析了jQuery中change方法的使用技巧,需要的朋友可以参考下

本文实例讲述了jQuery实现复选框成对选择及对应取消的方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:
<!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实现复选框成对选择,对应取消功能</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组</p>
<input type="checkbox" class="classA">
<input type="checkbox" class="classA">
<p>B组</p>
<input type="checkbox" class="classB">
<input type="checkbox" class="classB">
</body>
</html>

希望本文所述对大家的jQuery程序设计有所帮助。

相关文章

最新评论