zoukankan      html  css  js  c++  java
  • 全选、全不选、反选

    <script language="javascript" type="text/javascript">  
            $(function () {  
                $("#selectAll").click(function () {//全选  
                    $("#playList :checkbox").attr("checked", true);  
                });  
      
                $("#unSelect").click(function () {//全不选  
                    $("#playList :checkbox").attr("checked", false);  
                });  
      
                $("#reverse").click(function () {//反选  
                    $("#playList :checkbox").each(function () {  
                        $(this).attr("checked", !$(this).attr("checked"));  
                    });  
                });  
            });  
        </script> 
    <div id="playList">  
            <input type="checkbox" value="歌曲1" />歌曲1<br />  
            <input type="checkbox" value="歌曲2" />歌曲2<br />  
            <input type="checkbox" value="歌曲3" />歌曲3<br />  
            <input type="checkbox" value="歌曲4" />歌曲4<br />  
            <input type="checkbox" value="歌曲5" />歌曲5<br />  
            <input type="checkbox" value="歌曲6" />歌曲6  
        </div>  
        <input type="button" value="全选" id="selectAll" />  
        <input type="button" value="全不选" id="unSelect" />  
        <input type="button" value="反选" id="reverse" /> 

    第二种:全选(.prop只在jquery.1.6之后才有)

    <script language="JavaScript">
    $(function() {
    $("#ckAll").click(function() {
        $("input[name='sub']").prop("checked", this.checked);
      });
     
     
    });
    </script>
    <input type="checkbox" id="ckAll" />check all<br />
    <input type="checkbox" name="sub" />1<br />
    <input type="checkbox" name="sub"/>2<br />
    <input type="checkbox" name="sub"/>3<br />
    <input type="checkbox" name="sub"/>4<br />
  • 相关阅读:
    程序修炼之道——从小工到专家(3)
    组合
    子类重用父类的功能
    对象之间的交互
    属性查找与绑定方法
    类与对象的定义与使用
    hashlib模块subprocess模块
    configerparser模块
    shelve模块 xml模块
    sys模块 json pickle模块
  • 原文地址:https://www.cnblogs.com/Truke/p/3465634.html
Copyright © 2011-2022 走看看