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/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值