为什么FF不支持currentStyle?
代码如下:
CSS:
/*定义页面左列样式*/
#left {
POSITION: absolute;
LEFT: 0px;
WIDTH: 200px;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND: #CDCDCD;
border: 1px solid red;
height:100%;
} /*定义页面中列样式*/
#middle {
POSITION: absolute;
LEFT: 200px;
TOP: 0px;
WIDTH: 300px;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND: #DADADA;
border: 1px solid yellow;
} /*定义页面右列样式*/
#right {
POSITION: absolute;
LEFT: 500px;
TOP: 0px;
WIDTH: 280px;
MARGIN: 0px;
PADDING: 0px;
BACKGROUND: #FFF;
border: 1px solid blue;
}
、
HTML代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml " lang= "GBK ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GBK " />
<title> Insert title here </title>
<link rel= "stylesheet " href= "css/layout.css " type= "text/css "> </link>
</head>
<body>
<div id= "left ">
页面左列
</div>
<div id= "middle ">
页面中列
</div>
<div id= "right ">
页面右列
</div>
<script type= "text/javascript ">
alert(document.getElementById( "left ").currentStyle.height);
</script>
</body>
</html>
为什么上面的代码,在IE里输出来是100%, 而FF一点动静都没有,什么者没输出?
这是什么原因啊?
[解决办法]
currentStyle is just for IE5.0+
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 测试取色 </title>
<script type= "text/javascript ">
(function (bool) {
//兼容FF一些方法
if (bool) {
HTMLElement.prototype.__defineGetter__( "currentStyle ", function () {
return this.ownerDocument.defaultView.getComputedStyle(this, null);
});
}
})(/Firefox/.test(window.navigator.userAgent));
</script>
<style type= "text/css ">
.bg {
background-color:#000000;
}
</style>
</head>
<body>
<div class= "bg " id= "wc "> </div>
<input type= "button " value= "list currentStyle " onclick= "alert(document.getElementById( 'wc ').currentStyle.backgroundColor + '\n ') " />
</body>
</html>