0
点赞
收藏
分享

微信扫一扫

js javascript 遍历页面上所有的控件,包括服务器端的控件,然后获取相应的ID


获得所有控件ID

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.form[0].elements;

for(i=0;i <arrAll.length;i++)
{
     var strId += '- '+arrAll[i].id;
}




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代码


<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代码


<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()" />




黑色头发:http://heisetoufa.iteye.com/


举报

相关推荐

Node.js之创建TCP服务器端

0 条评论