样式里的宽度为小数,js获取其值
文章目录
<input type="button" value="动起来" id="btn" />
<div id="div1" style="width:100.5px; height: 100px; background: red; position: absolute; left: 100px; top: 30px;"></div>
<div style="width:100px; height: 100px; background: black; position: absolute; left:100px; top: 120px; "></div>
js代码:
window.onload = function() {
var oBtn = document.getElementById('btn');
var oDiv = document.getElementById('div1');
alert( oDiv.offsetWidth );//四舍五入运算
}
通过实验我们发现,样式可以设置为小数,但是js获取其值的时候,会进行四舍五入。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论