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

怎么读取层的top和left并更改

2012-06-14 
如何读取层的top和left并更改div classright stylewidth: 1575px height1000pxdiv algincent

如何读取层的top和left并更改
<div class="right" style='width: 1575px; height=1000px'>
<div algin="center" id='hiddenPic' style='position:absolute; z-index:1; visibility: hidden; left:200px; top:90px; width:0px; height:0px; '>
<img name='imagehide' id="images2" width="560" src='./images/test.jpg' border='0' onload="return imgzoom(this,600); style="cursor:pointer;" alt=""/></div>

<div colspan="4" algin="center" id='block1' onmouseout='drag=0' onmouseover='dragObj=block1; drag=1;' style='z-index:0; left:200px; top:90px; width:0px; height:0px; position: relative;' class="dragAble">
<img name='imageshow' id="images1" width="560" src='./images/test.jpg' border='0' onload="return imgzoom(this,600); style="cursor:pointer;" alt=""/></div> 
</div>


如何用函数读取id=block1的top和left
并更改它

注:需符合w3c格式,且兼容FF

[解决办法]

HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>    <script>        $(function () {            alert($("#block1").css("top"));            alert($("#block1").css("left"));            $("#block1").css("top", "150px");            $("#block1").css("left", "450px");        })    </script></head><body>    <div class="right" style='width: 1575px; height=1000px'>        <div algin="center" id='hiddenPic' style='position: absolute; z-index: 1; visibility: hidden;            left: 200px; top: 90px; width: 0px; height: 0px;'>            <img name='imagehide' id="images2" width="560" src='./images/test.jpg' border='0'                onload="return imgzoom(this,600);" style="cursor: pointer;" alt="" />        </div>        <div colspan="4" algin="center" id='block1' onmouseout='drag=0' onmouseover='dragObj=block1; drag=1;'            style='z-index: 0; left: 200px; top: 90px; width: 0px; height: 0px; position: relative;'            class="dragAble">            <img name='imageshow' id="images1" width="560" src='./images/test.jpg' border='0'                onload="return imgzoom(this,600);" style="cursor: pointer;" alt="" /></div>    </div></body></html>
[解决办法]
document.getElementById("block1").style.top
这样就行了呀。

热点排行