一个全选按钮js的案例

<html>
<head>
<script type="text/javascript">   
 
    // 全选按钮选中标志  
    var checkflag = "false";  
    // 全选功能  
    function selectAll(name){  
        var field = document.getElementsByName(name);  
        // 如果全选按钮状态是未选中  
        if (checkflag == "false"){  
            for (i = 0; i < field.length; i++){  
                field[i].checked = true;  
            }  
            // 更改全选按钮选中标志  
            checkflag = "true";  
        }else{  
            for (i = 0; i < field.length; i++){  
                field[i].checked = false;   
            }  
            // 更改全选按钮选中标志  
            checkflag = "false";  
        }  
    }  
 
</script> 
</head>
<body>
<form name="form" method="post" action=""> 
    <table> 
        <tr> 
            <td> 
                <input type="checkbox" value="全选" onClick="selectAll(‘list‘)">选中所有显示记录   
            </td> 
        </tr> 
        <tr> 
            <td> 
                <input type="checkbox" name="list" value="1" > 
            </td>       
        </tr> 
        <tr> 
            <td> 
                <input type="checkbox" name="list" value="2"> 
            </td>       
        </tr> 
        <tr> 
            <td> 
               <input type="checkbox" name="list" value="3"> 
            </td>       
        </tr> 
    </table> 

</form> 
</body>
</html>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。