jquery 1.6以上版本 全选

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>全选,不全选,反选</title>
   <script src="jquery.js" type="text/javascript"></script>
   <script src="jquery.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
         $(function() {
           $("#checkAll").click(function() {
                $('input[name="subBox"]').prop("checked",this.checked); 
    console.log( $('input[name="subBox"]'));
    
            });
        });
    </script>
</head>
<body>
    <div id="playList">
        <input type="checkbox" name='subBox' value="歌曲1" />歌曲1<br />
        <input type="checkbox" name='subBox' value="歌曲2" />歌曲2<br />
        <input type="checkbox" name='subBox' value="歌曲3" />歌曲3<br />
        <input type="checkbox" name='subBox' value="歌曲4" />歌曲4<br />
        <input type="checkbox" name='subBox' value="歌曲5" />歌曲5<br />
        <input type="checkbox" name='subBox' value="歌曲6" />歌曲6
    
    <input type="checkbox" value="全选" id="checkAll" />
    <input type="button" value="全不选" id="unSelect" />
    <input type="button" value="反选" id="reverse" />
 </div>
</body>
</html>

attributesproperties之间的差别在特定状况下是很重要。jQuery 1.6以前 .attr()方法在取某些 attribute 的值时,会返回 property 的值,这就致使告终果的不一致。从 jQuery 1.6 开始 .prop()方法 方法返回 property 的值,而.attr() 方法返回 attributes 的值。javascript

相关文章
相关标签/搜索