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

JS 遍历页面下所有的控件

2012-06-29 
JS 遍历页面上所有的控件获得所有控件ID Html代码var arrAlldocument.allfor(i0i arrAll.lengthi++)

JS 遍历页面上所有的控件

获得所有控件ID Html代码  var arrAll=document.all;     for(i=0;i <arrAll.length;i++)   {       alert(arrAll[i].id);       alert(arrAll[i].name);         if(arrAll[i].id== '... ')         {             //   do   something         }   }  var arrAll=document.all;for(i=0;i <arrAll.length;i++){    alert(arrAll[i].id);    alert(arrAll[i].name);      if(arrAll[i].id== '... ')      {          //   do   something      }}Html代码  var arrAll=document.form[0].elements;     for(i=0;i <arrAll.length;i++)   {        var strId += '- '+arrAll[i].id;   }  var arrAll=document.form[0].elements;for(i=0;i <arrAll.length;i++){     var strId += '- '+arrAll[i].id;}Html代码  var arrAll=document.all;     for (i=0;i <arrAll.length;i++)   {       if(arrAll[i].name == 'label')       {           document.getElementById(arrAll[i].id).style.color = "black";       }   }  var arrAll=document.all;for (i=0;i <arrAll.length;i++){    if(arrAll[i].name == 'label')    {        document.getElementById(arrAll[i].id).style.color = "black";    }}鼠标选择控件,使控件变颜色,并且用4个按钮改变多个控件的位置 js代码 Js代码  <script type="text/javascript" >         var labelID = "";         function moveTop()       {          var a=document.getElementById(labelID).style.top;          var Top=a.substring(0,a.indexOf("px"));          document.getElementById(labelID).style.top= parseInt(Top)-10;// 向上       }       function moveUnder()       {          var a=document.getElementById(labelID).style.top;          var Top=a.substring(0,a.indexOf("px"));          document.getElementById(labelID).style.top= parseInt(Top)+10;// 向下       }       function moveLeft()       {          var b=document.getElementById(labelID).style.left;          var Left=b.substring(0,b.indexOf("px"));          document.getElementById(labelID).style.left= parseInt(Left)-10;// 向左       }       function moveRight()       {          var b=document.getElementById(labelID).style.left;          var Left=b.substring(0,b.indexOf("px"));          document.getElementById(labelID).style.left= parseInt(Left)+10;// 向右边       }       function getID(labelIDCS)       {          labelID = labelIDCS;            var arrAll=document.all;            for (i=0;i <arrAll.length;i++)          {              if(arrAll[i].name == 'label')              {                  document.getElementById(arrAll[i].id).style.color = "black";              }          }          document.getElementById(labelID).style.color = "red";       }   </script>  <script type="text/javascript" >    var labelID = "";    function moveTop()    {       var a=document.getElementById(labelID).style.top;       var Top=a.substring(0,a.indexOf("px"));       document.getElementById(labelID).style.top= parseInt(Top)-10;// 向上    }    function moveUnder()    {       var a=document.getElementById(labelID).style.top;       var Top=a.substring(0,a.indexOf("px"));       document.getElementById(labelID).style.top= parseInt(Top)+10;// 向下    }    function moveLeft()    {       var b=document.getElementById(labelID).style.left;       var Left=b.substring(0,b.indexOf("px"));       document.getElementById(labelID).style.left= parseInt(Left)-10;// 向左    }    function moveRight()    {       var b=document.getElementById(labelID).style.left;       var Left=b.substring(0,b.indexOf("px"));       document.getElementById(labelID).style.left= parseInt(Left)+10;// 向右边    }    function getID(labelIDCS)    {       labelID = labelIDCS;       var arrAll=document.all;       for (i=0;i <arrAll.length;i++)       {           if(arrAll[i].name == 'label')           {               document.getElementById(arrAll[i].id).style.color = "black";           }       }       document.getElementById(labelID).style.color = "red";    }</script>asp HTML代码 Html代码  <asp:Label ID = "lblDSRText" Text = "当事人" runat = "server" name="label" Style="left: 280px; position: absolute;top: 262px" onclick="getID('lblDSRText')" Width="38px" ></asp:Label>  <asp:Label ID = "lblDSRXMText" Text = "当事人姓名" runat = "server" name="label" Style="left: 541px; position: absolute;top: 262px" onclick="getID('lblDSRXMText')" Width="61px"></asp:Label>    <asp:ImageButton ID = "ibnSY" runat = "server" ImageUrl="~/imgs/top.GIF" onclick="moveTop()" />  <asp:ImageButton ID = "ibnXY" runat = "server" ImageUrl="~/imgs/down.GIF" onclick="moveUnder()" />  <asp:ImageButton ID = "ibnZY" runat = "server" ImageUrl="~/imgs/left.GIF" onclick="moveLeft()" />  <asp:ImageButton ID = "ibnYY" runat = "server" ImageUrl="~/imgs/right.GIF" onclick="moveRight()" />  <asp:Label ID = "lblDSRText" Text = "当事人" runat = "server" name="label" Style="left: 280px; position: absolute;top: 262px" onclick="getID('lblDSRText')" Width="38px" ></asp:Label><asp:Label ID = "lblDSRXMText" Text = "当事人姓名" runat = "server" name="label" Style="left: 541px; position: absolute;top: 262px" onclick="getID('lblDSRXMText')" Width="61px"></asp:Label><asp:ImageButton ID = "ibnSY" runat = "server" ImageUrl="~/imgs/top.GIF" onclick="moveTop()" /><asp:ImageButton ID = "ibnXY" runat = "server" ImageUrl="~/imgs/down.GIF" onclick="moveUnder()" /><asp:ImageButton ID = "ibnZY" runat = "server" ImageUrl="~/imgs/left.GIF" onclick="moveLeft()" /><asp:ImageButton ID = "ibnYY" runat = "server" ImageUrl="~/imgs/right.GIF" onclick="moveRight()" />
?

热点排行