`

有关全选、反选、取消 的jquery效果

阅读更多

做一个全选、反选、取消的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" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<script type="text/javascript" src="jquery.js"></script>
<title>checekBox全选\反选控制</title>
<style type="text/css">
   *{ margin:0 ; padding:0; font-size:12px;}
   .main{ width:500px; margin:50px auto;}
   input { margin:5px;}
</style>
</head>
<body>
<div>

 <div class="main">
    <h2>个人爱好:</h2>
    <input type="checkbox" name="check"   />十字绣
    <input type="checkbox" name="check" />看时尚杂志
    <input type="checkbox" name="check"  />球类运动
    <input type="checkbox" name="check" />看电视
    <input type="checkbox" name="check"  />看书
    <input type="checkbox" name="check" />爬山

<br/>
 <a href="javascript:void(0);" onclick="checkAll(this);"/>全选</a>
 <a href="javascript:void(0);" onclick="checkAll(this,2);"/>反选</a>
 <a href="javascript:void(0);" onclick="checkAll(this,1);"/>全部取消</a>
 </div>
</body>
</html>
<script language="javascript">

function checkAll(obj,type)
{
//首先捕获需要控制的区域,需要有dom的知识
var goalArea=$(obj).parent();
$("input[@name='check']", goalArea).each
(
   function ()
   {
    if(type==1)
    {
     //全部取消
     $(this).attr("checked", false);
    }
    else if(type==2)
    {
     //反选
     $(this).attr("checked", $(this).attr("checked")==true?false:true);
    }
    else
    {
     //全选
     $(this).attr("checked", true);
    }
   }
)
}

</script>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics