首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JS惯用代码,checkbox全选/全不选

2012-10-27 
JS常用代码,checkbox全选/全不选html xmlnshttp://www.w3.org/1999/xhtmlheadmeta http-equivCo

JS常用代码,checkbox全选/全不选
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
p {margin:0;font-size:12px;line-height:26px;}
</style>
<script type="text/javascript">
function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++){
       checkboxs[i].checked = obj.checked;
    }
}
</script>
</head>

<body>
<p><input type="checkbox" name="all" onclick="check_all(this,'c')" />全选/全不选</p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
</body>
</html>

热点排行