读书人

求个JS 点击的代码,该如何处理

发布时间: 2012-03-22 17:43:57 作者: rapoo

求个JS 点击的代码
有两个单选框(HTML控件) id= "select " name= "select " 一个为管理员 一个为普通用户

然后下面列出的是N复选框id= "classid ",name= "classid " value= "* ",要求当点击管理员的时候这N个复选框就都被选中,当点际普通用户的时候就全部不选中,,

请问有各们能给个代码么

[解决办法]
<input type=radio onclick= "S(true) "> 管理员
<input type=radio onclick= "S(false) "> 用户员

<input type=checkbox name= "classid ">
<input type=checkbox name= "classid ">
<input type=checkbox name= "classid ">

<script>
function S(b)
{
bx = document.getElementsByName( "classid ")
for(i = 0;i <bx.length;i++)
bx[i].checked=b
}
</script>
[解决办法]
<div>
<select onchange= "ChooseAll(this.options[this.selectedIndex].value) "> <option value= "0 "> 请选择 </option> <option value= "1 "> 管理员 </option> <option value= "2 "> 用户 </option> </select>
</div> <input type=checkbox>
<input type=checkbox>
<input type=checkbox>
<input type=checkbox>
<input type=checkbox>
<script type= "text/javascript ">
var checkFlag = true;
    function ChooseAll(obj)
    {
     if(obj== "1 ")
     checkFlag=true;
     else
     checkFlag=false;
      if( checkFlag ) // 全选 
      {
        var inputs = document.all.tags( "INPUT ");
        for (var i=0; i < inputs.length; i++) // 遍历页面上所有的 input
        {
          if (inputs[i].type == "checkbox " && inputs[i].id != "CheckAll " )
          {
            inputs[i].checked = true;
          }
        }
        checkFlag = false;
      }
      else // 取消全选
      {
        var inputs = document.all.tags( "INPUT ");
        for (var i=0; i < inputs.length; i++) // 遍历页面上所有的 input
        {
          if (inputs[i].type == "checkbox " && inputs[i].id != "CheckAll " )
          {
            inputs[i].checked = false;
          }
        }
        checkFlag = true;
      }
    }
</script>
[解决办法]
孟老大的成功率还真高,楼上的先把题看清楚...

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<script type= "text/javascript " language= "javascript ">
function S(b)
{
bx = document.getElementsByName( "classid ")
for(i = 0; i < bx.length; i++)
bx[i].checked = b
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<input type= "radio " onclick= "S(true) " /> 管理员
<input type= "radio " onclick= "S(false) " /> 普通用户
<input type= "checkbox " name= "classid " />
<input type= "checkbox " name= "classid " />
<input type= "checkbox " name= "classid " />


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

[解决办法]
呵呵,不好意思,我看到select还以为,汗一个
[解决办法]
其实,需求都出来了...很简单的问题...熟悉一下js就可以了...
看来分数都被上面几位给...^_^

读书人网 >asp.net

热点推荐