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

关于如何取控件的XY坐标

2012-02-08 
关于怎么取控件的XY坐标!scriptfunctionshowXY(obj){alert( X: +obj.style.top+ \n\nY: +obj.style.

关于怎么取控件的XY坐标!
<script>
function   showXY(obj){
alert( "X: "+obj.style.top+ "\n\nY: "+obj.style.left)
}
</script>
<input   type= "text "   onClick= "showXY(this) "> <input   type= "text "   onClick= "showXY(this) "> <br>
<input   type= "text "   onClick= "showXY(this) ">

[解决办法]
<script>
function showXY(obj){
alert( "X: "+obj.offsetTop+ "\n\nY: "+obj.offsetLeft);
}
</script>
<input type= "text " onClick= "showXY(this) "> <input type= "text " onClick= "showXY(this) "> <br>
<input type= "text " onClick= "showXY(this) ">

热点排行