js 获取DIV宽 并赋值给另一个DIV
1个回答
展开全部
<style type="text/css">
#div1{width:100px;height:100px;}
<style>
<div id="div1">1212</div>
<div id="div2">3434</div>
<script>
function getStyle(obj,attribute){//获取样式
return obj.currentStyle?obj.currentStyle[attribute]/*ie*/:document.defaultView.getComputedStyle(obj,null)[attribute]/*ie9 火狐 谷歌*/;
}
var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
var wid = getStyle(div1,"width")
div2.onmouseover = function(){//鼠标移到div2时设置宽度
this.style.width = wid;
};
</script>
#div1{width:100px;height:100px;}
<style>
<div id="div1">1212</div>
<div id="div2">3434</div>
<script>
function getStyle(obj,attribute){//获取样式
return obj.currentStyle?obj.currentStyle[attribute]/*ie*/:document.defaultView.getComputedStyle(obj,null)[attribute]/*ie9 火狐 谷歌*/;
}
var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
var wid = getStyle(div1,"width")
div2.onmouseover = function(){//鼠标移到div2时设置宽度
this.style.width = wid;
};
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询