日期:2014-05-16  浏览次数:20373 次

如何读取层的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
这样就行了呀。