随笔-72  评论-63  文章-0  trackbacks-0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<input type=checkbox name=mm value=a onclick="checkItem(this, 'mmAll')"><br>
<input type=checkbox name=mm value=b onclick="checkItem(this, 'mmAll')"><br>
<input type=checkbox name=mm value=c onclick="checkItem(this, 'mmAll')"><br>
<input type=checkbox name=mm value=d onclick="checkItem(this, 'mmAll')"><br>
<input type=checkbox name=mm value=e onclick="checkItem(this, 'mmAll')"><br><br>
<input type=checkbox name=mmAll onclick="checkAll(this, 'mm')">全选与不全选的切换
<input name='button1' type='button' value='全选' onClick='this.value=check("mm")'>

<script language="javascript">
var checkflag="false";
function check(field){
field = document.getElementsByName(field)
        if(checkflag=="false"){
                for(i=0;i<field.length;i++)
                {
                        field[i].checked = true;
                }
                checkflag="true";
                return "反选";
        }
        else {
                for(i=0;i<field.length;i++)
                {
                        field[i].checked = false;
                }
                checkflag="false";
                return "全选";
        }
}
</script>


<script language=Javascript>
function checkAll(e, itemName)
{
  var aa = document.getElementsByName(itemName);
  for (var i=0; i<aa.length; i++)
   aa[i].checked = e.checked;
}
function checkItem(e, allName)
{
  var all = document.getElementsByName(allName)[0];
  if(!e.checked) all.checked = false;
  else
  {
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
  }
}
</script>

 

</body>
</html>

posted on 2006-05-17 13:51 船长 阅读(274) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: