<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获取其值的时刻,会举行四舍五入。