currentStyle以及getComputeStyle方法获取元素高度实例页面
回到相关文章 »代码:
CSS代码:
.button { height: 2em; border: 0; border-radius: .2em; background-color: #34538b; color: #fff; font-size: 12px; font-weight: bold; }
HTML代码:
<input type="button" id="button" class="button" value="点击我,显示高度" />
JS代码:
document.getElementById("button").onclick = function() { var oStyle = this.currentStyle? this.currentStyle : window.getComputedStyle(this, null); alert(oStyle.height); };