
首先你的代码写错了<div
id="banner"
style="width:100%">这样写才是正确的
js获取banner的宽度:documentgetElementById("banner")offsetWidth
jq获取banner的宽度:$("#banner")width();
<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 objcurrentStyleobjcurrentStyle[attribute]/ie/:documentdefaultViewgetComputedStyle(obj,null)[attribute]/ie9 火狐 谷歌/;
}
var div1 = documentgetElementById("div1");
var div2 = documentgetElementById("div2");
var wid = getStyle(div1,"width")
div2onmouseover = function(){//鼠标移到div2时设置宽度
thisstylewidth = wid;
};
</script>
给div设置一个id或者class:
html部分:
<div id="mydiv"></div>
js部分:
<script>
//获取mydiv
var mydiv=documentgetElementById("mydiv");
//获取#mydiv的高度
var divheight=mydivstyleheight;
//设置mydiv行高
mydivstylelineHeight=divheight;
</script>
javascript获取div的class中设置的宽高度:
高度(offsetHeight):
<head><title>用js获取div的高度</title></head><style type="text/css">
#box{border:1px solid #ff0000;width:200px; }
</style>
<script language="javascript">
function jj(){
var pp=documentgetElementById("box")offsetHeight;
alert(pp);
}
</script>
<body>
<div id="box">
<p>段落内容</p><p>段落内容</p>
<input type="button" onclick="jj();" value="click">
</div>
</body>
宽度(offsetWidth):
<head><title>用js获取div的高度</title></head><style type="text/css">
#box{border:1px solid #ff0000;width:200px; }
</style>
<script language="javascript">
function jj(){
var pp=documentgetElementById("box")offsetWidth;
alert(pp);
}
</script>
<body>
<div id="box">
<p>段落内容</p><p>段落内容</p>
<input type="button" onclick="jj();" value="click">
</div>
</body>
// 通过id获取控件,offsetWidth为控件实际展现宽度。
<div id="divId" style="float: left">1111111111111</div>
var width = documentgetElementById("divId")offsetWidth;
alert(width);
右侧的“查询”请设置style="float:right"
让”查询“靠右显示,就ok了。
(function(){
var option ={"auto_play":"0","file_id":"16092504232103639705","app_id":"1251580615","width":screenwidth,"height":screenheight}; /调用播放器进行播放/
new qcVideoPlayer( /代码中的id_video_container将会作为播放器放置的容器使用,可自行替换/ "id_video_container", option ); })()
以上就是关于div中 宽度是百分比显示的,怎么在js中获取这个宽度呢全部的内容,包括:div中 宽度是百分比显示的,怎么在js中获取这个宽度呢、js 获取DIV宽 并赋值给另一个DIV、JS怎么获取div(高度和宽度都已设置百分比,继承父级)的height并应用于该div的line-height;等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)