热门文章 | 热门软件| 热门源码 | 热门电影 | 知识库 | 联系我们
软件 源码 教程 影视 健康 招聘
  HTML | JavaScript | ASP | PHP | JSP | NET | VB | VC | VF | Windows | Linux | Mysql | Mssql | Oracle | Struts 
当前位置: 创世纪计算机资源网 -> 文章频道 ->js 
站内搜索:
如何利用javascript实现复选框全选
作者:大灰狼 来源:http://www.gold98.net/blog 整理日期:2007-3-29

预览地址:http://www.gold98.net/blog/upfile/testchecked.html

下面只是实现利用javascript实现复选框全选的一种方法,还有其它很多方法,这就需要大家慢慢探索了~

<script language="javascript">
function chkAll_onclick(){
if(typeof(form1.chkAccount) == "object"){
if(form1.chkAllAccount.checked){
SelAll();
}
else{
unSelAll();
}
}
}
function SelAll(){
var intCount;
        var result="";
if(form1.all("chkAccount").length > 1)
        {
for(intCount = 0; intCount < form1.all("chkAccount").length; intCount++)
                {
form1.chkAccount(intCount).checked = true;
                        result=result+form1.chkAccount(intCount).value+";";    
}
}
else{
form1.chkAccount.checked = true;
}

        alert("你选中的是:"+result);
}

function unSelAll(){
var intCount;
if(form1.all("chkAccount").length > 1)
        {
for(intCount = 0; intCount < form1.all("chkAccount").length; intCount++)
                {
form1.chkAccount(intCount).checked = false;
}
}
else{
form1.chkAccount.checked = false;
}
}
</script>
<form name="form1" method="post" action="">
<input name="chkAccount" type="checkbox" value="人民"/>人民
<input name="chkAccount" type="checkbox" value="中国"/>中国
<input name="chkAccount" type="checkbox" value="你好"/>你好
<input name="chkAccount" type="checkbox" value="公园"/>公园
<input name="chkAccount" type="checkbox" value="长江"/>长江
<input name="chkAccount" type="checkbox" value="黄河"/>黄河
<input type="checkbox" name="chkAllAccount" value="ON" title="全部选中" onclick="chkAll_onclick()">全部选中

</form>

相关文章