日期:2014-05-16 浏览次数:20427 次
原来代码如下:
CSS Code:
<style type="text/css">
#dd{width:100px; height:100px; background:green; padding:10px; border:10px solid red; }
</style>
Xhtml Code:
<div id="dd" >dd</div>
Javascript Code:
<script>
window.onload=function(){
alert(document.getElementById("dd").style.height);
??? }
</script>
弹出框结果为空!Why?
现在,还是原来的javascript代码,我将CSS和XHMTL代码稍微一下:
CSS Code:
<style type="text/css">
#dd{ background:green; padding:10px; border:10px solid red; }
</style>
Xhtml Code :(将宽和高的样式写在这里)
<div id="dd" style="width:100px; height:100px;" >dd</div>
弹出框结果为100px!,Why ??
难道与CSS权重有关?百思不得其解!先记录下来,以后找答案!
if (!window.getComputedStyle) { window.getComputedStyle = function(el, pseudo){ this.el = el; this.getPropertyValue = function(prop){ var re = /(\-([a-z]){1})/g; if (prop == 'float') prop = 'styleFloat'; if (re.test(prop)) { prop = prop.replace(re, function(){ return arguments[2].toUpperCase(); }); } return el.currentStyle[prop] ? el.currentStyle[prop] : null; } return this; } }