当前位置:编程学习 > C#/ASP.NET >>

js中style.top与style.left无效

function SetShowById(divId,isShow)
    {
        var objDiv=document.getElementById(divId);
        if(isShow==1)
        {
           
           objDiv.style.display="block";
           objDiv.style.top = "300px";
           objDiv.style.left = "300px";
        }
        else
        {
           objDiv.style.display="none";
        }
    }

谁能看下,为什么objDiv.style.top = "300px"与objDiv.style.left = "300px"无效呢? --------------------编程问答-------------------- 没有设置position用top和left无效
换成
margin-top,margin-left --------------------编程问答-------------------- var div=document.getElementById("div的id");
div.style.left="10px";
div.style.top=10; --------------------编程问答--------------------

<div style="background-color:Gray; width:200px; height:100px;position: absolute;" id="testDiv"><br />
        <input id="Button1" type="button" value="button" onclick="SetShowById('testDiv',1)"; />
    </div>


注意加红色标记这一句 --------------------编程问答-------------------- position: absolute; --------------------编程问答--------------------
引用 4 楼 wanghuaide 的回复:
position: absolute;
--------------------编程问答-------------------- 帮顶!!!!!!证明存在 --------------------编程问答-------------------- 可以了,谢谢大家,还是csdn能找到帮助! --------------------编程问答-------------------- position: absolute;
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,