日期:2014-05-16 浏览次数:20513 次
<html>
<head>
<title>test</title>
<style>
ul li{
float:left;
}
</style>
</head>
<body>
<ul id="myul">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<script language="javascript">
var nodes = this.myul.childNodes;
for (var i = 0 ; i < nodes.length ; i++ ){
var node = nodes[i];
node.onmouseover = function() {
node.style.backgroundColor = "red";
}
}
</script>
</body>
</html>
var nodes = this.myul.childNodes;
for (var i = 0 ; i < nodes.length ; i++ ){
var node = nodes[i];
node.onmouseover = function() {
this.style.backgroundColor = "red";
}
node.onmouseout = function() {
this.style.backgroundColor = "transparent";
}
}