根据坐标定位并显示div window.onloadfunction(){varobjdocument.getElementById( btnID )if(obj!nu
根据坐标定位并显示div
window.onload=function() {
var obj=document.getElementById( "btnID ");
if(obj != null)
{
//显示坐标(130,15)
obj.style.pixelLeft=130;//x坐标
obj.style.pixelTop=15; //y坐标
}
}
函数window.onload=function()目的是待网页加载完毕然后才执行,控制id= "btnID "的按钮显示位置,但是刷新页面时,按钮依然在原始位置,只有在点击该按钮时,才能在坐标(130,15)处显示,如何做到网页加载完毕,按钮立即在坐标(130,15)处显示?
[解决办法]
- HTML code
<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> </head><body><input id="btnID" type="button" value="ssss" style=" position:relative"/><script> window.onload = function () { var obj = document.getElementById("btnID"); if (obj != null) { //显示坐标(130,15) obj.style.top = '130px'; //x坐标 obj.style.left = '15px'; //y坐标 } } </script></body></html> 