标签:blog 表达式 代码 round images ack cti foo 分享
<style>
div {
width: 200px;
height: 200px;
background: red;
margin-top: 20px;
}
</style>
</head>
<body>
<div id="header" >行间事件</div>
<div id="main">this的作用</div>
<div id="footer">JS事件</div>
<script>
var header=document.getElementById("header"),
footer=document.getElementById("footer"),
main=document.getElementById("main");
toGreen();//在函数toGreen之前之后都可以
function toGreen(){
header.style.background="green";
}
var toBlue=function(){
footer.style.background="blue";
}
footer.onclick=toBlue;//只能在toBlue之后不能再之前,因为代码是从上向下执行的toBlue相当于一个变量,在其之前则toBlue是undefined;
main.onclick=function(){
//在这行代码中this等价于main
this.style.background="orange";
}
</script>

标签:blog 表达式 代码 round images ack cti foo 分享
原文地址:http://www.cnblogs.com/xingkongly/p/7576910.html