通过javascript更改div的位置 [英] Change the position of div through the javascript

查看:62
本文介绍了通过javascript更改div的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个div控件.
在某种情况下,我显示第一个div并隐藏第二个div.
当我隐藏第一个div并显示第二个div时,第二个div不会更改位置.
如何将第二个div位置更改为第一个div.

I have a two div controls.
In a condition I show the first div and hide the second div.
When I hide the first div and show the second div, the second div does not change the location.
How can I change the second div position to first div.

if(value==1)
{
 document.getElementById("div1").style.visibility = ''hidden'';
 document.getElementById("div2").style.visibility = ''visible'';
}
else
{
 document.getElementById("div1").style.visibility = ''visible'';
 document.getElementById("div2").style.visibility = ''hidden'';
}


需要在div1的位置显示div2.


Need to show the div2 at the position of div1.

推荐答案

获得解决方案

if(value === 1)
{
document.getElementById("div2").style.display =``'';
document.getElementById("div1").style.display =``none'';
document.getElementById("div2").style.visibility ="visible";

}
其他
{
document.getElementById("div1").style.display ='''';
document.getElementById("div1").style.visibility ="visible";
document.getElementById("div2").style.display =``none'';
}
Got the solution

if(value===1)
{
document.getElementById("div2").style.display = '''';
document.getElementById("div1").style.display = ''none'';
document.getElementById("div2").style.visibility = ''visible'';

}
else
{
document.getElementById("div1").style.display='''';
document.getElementById("div1").style.visibility = ''visible'';
document.getElementById("div2").style.display = ''none'';
}


您还需要使用位置 [ ^ ]样式属性以及顶部和左侧.
You need also to use the position[^] style attribute, along with top and left.


这篇关于通过javascript更改div的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆