兼容的话题:currentStyle
马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。
例 2.3.1
<!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=utf-8"/>
<title></title>
<style type="text/css">
#mydiv {
background-color: #28F;
width: 400px;
height: 200px;
}
</style>
<script type="text/javascript">
window.onload = function() {
ob = document.getElementById('mydiv');
alert("document.all is"+ document.all);
if (document.all) {
alert("current is ie");
alert(ob.currentStyle.backgroundColor);
alert(ob.currentStyle.height);
ob.style.background="#FF3C31";
} else {
alert("current is Firefox");
alert(window.getComputedStyle(ob).getPropertyValue('background-color'));
alert(window.getComputedStyle(ob).getPropertyValue('height'));
ob.style.background="#FF3C31";
}
}
</script>
</head>
<body>
<div id="mydiv">马克-to-win</div>
</body>
</html>
例 2.3.2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style type="text/css">
#square {
/* 马克-to-win:for 美工 student, this example needs to be demoed to show how to
use dreamer. when do this experiment, we can directly use dreamweaver。note that we must first insert a layout
object/ div label.ID写drag,紧接着点击底下的“新建css样式”,高级ID,#drag,仅对该文档。
then must have 定位,类型,绝对, position:absolute;
上面这一步同样可以在html网页中, 任何时候点击右键:css样式/新建, 达到同样效果。
after finish the wizard, we can also change the css property by right-clicking the #drag in the right window.
then editing it.
*/
position: absolute;
border: solid 1px green;
background-color: #FFCCCC;
width: 200px;
left: 20px;
top: 20px;
height: 200px;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
<!--
function move(t)
{
if (document.all) {
var s="backgroundcolor is "+t.currentStyle.backgroundColor;
var s1="height is "+t.currentStyle.height;
var s2="position is "+t.currentStyle.position;
var s3="border is "+t.currentStyle.borderTopColor;
} else {
var s="backgroundcolor is "+window.getComputedStyle(t, null).getPropertyValue('background-color');
alert("s is "+s);
var s1="height is "+window.getComputedStyle(t, null).getPropertyValue('height');
alert("s1 is "+s1);
var s2="position is "+window.getComputedStyle(t, null).getPropertyValue('position');
alert("s2 is "+s2);
var s3="border is "+window.getComputedStyle(t, null).getPropertyValue('border-top-color');
alert("s3 is "+s3);
var s31="border is "+window.getComputedStyle(t, null).getPropertyValue('border-left-color');
alert("s31 is "+s31);
var s33="border is "+window.getComputedStyle(t, null).getPropertyValue('border-left-style');
alert("s33 is "+s33);
var s4="width is "+window.getComputedStyle(t, null).getPropertyValue('width');
alert("s4 is "+s4);
var s5="left is "+window.getComputedStyle(t, null).getPropertyValue('left');
alert("s5 is "+s5);
var s6="top is "+window.getComputedStyle(t, null).getPropertyValue('top');
alert("s6 is "+s6);
}
/*下句也能工作*/
t.style.backgroundColor = "#FF8888";
t.style.backgroundColor="yellow";
t.style.background="#2A31EE";//前两个都被覆盖了
t.style.borderColor = "red";
t.style.borderWidth = "4px";
t.style.height = "150px";
t.style.left = "40px";
var s7="单步调试站位";
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<div id="square" ondblclick="move(this)">马克-to-win</div>
</BODY>
</HTML>