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

相關文章
相關標籤/搜索