码迷,mamicode.com
首页 > Web开发 > 详细

简单的js反选,全选,全不选

时间:2015-12-15 12:23:27      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP ‘check.jsp‘ starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    <input type="checkbox" id="boxid" onclick="selAllNo()">全选/全不选
    <hr>
    <input type="checkbox" name="love"/>篮球
    <input type="checkbox" name="love"/>足球
    <input type="checkbox" name="love"/>乒乓球
    <input type="checkbox" name="love"/>排球
    <input type="checkbox" name="love"/>保龄球
    <hr>
    <input type="button" name="checkedAll" onclick="selAll()" value="全选">
    <input type="button" name="checkedNo" onclick="selNo()" value="全不选">
    <input type="button" name="checkedOther" onclick="selOther()" value="反选">
    <script type="text/javascript">
        function selAll(){
            var loves = document.getElementsByName("love");
            
            for(var i=0;i<loves.length;i++){
                var love1 = loves[i];
                love1.checked = true;
            }
        }
        function selNo(){
            var loves = document.getElementsByName("love");
            
            for(var i=0;i<loves.length;i++){
                var love1 = loves[i];
                love1.checked = false;
            }
        }
        function selOther(){
            var loves = document.getElementsByName("love");
            for(var i=0;i<loves.length;i++){
                var love1 = loves[i];
                if(love1.checked==true){
                    love1.checked = false;
                }else{
                    love1.checked = true;
                }
            }
            
        }
        function selAllNo(){
            var boxid = document.getElementById("boxid");
            if(boxid.checked==true){
                selAll();
            }else{
                selNo();
            }
        }
    </script>
  </body>    
</html>

 

简单的js反选,全选,全不选

标签:

原文地址:http://www.cnblogs.com/invban/p/5047624.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!