var navLi = mainLeft.getElementsByTagName('a');
for(i=0; i< navLi.length; i++){
navLi[i].onclick=function(){
this.style.backgroundColor="#f0f0ee";
}
}
我要做的是点击元素事件, 还有除了点击元素之外的元素事件。
简单地说就是当前点击元素加个背景, 其他元素打回原型。
就是菜单栏加亮效果, 我是在iframe做的,用于后台。 大师门请指教啊。
<html>
<head>
</head>
<body>
<div id="mainLeft">
<a>123</a> <a>234</a> <a>345</a> <a>456</a>
</div>
</body>
</html>
<script type="text/javascript">
var navLi = mainLeft.getElementsByTagName('a');
function hy() {
for (i = 0; i < navLi.length; i++) {
navLi[i].style.backgroundColor = "#FFF";
}
}
for (i = 0; i < navLi.length; i++) {
navLi[i].onclick = function() { hy(); this.style.backgroundColor = "#FF0"; }
}
</script>
<head>
</head>
<body>
<div id="mainLeft">
<a>123</a> <a>234</a> <a>345</a> <a>456</a>
</div>
</body>
</html>
<script type="text/javascript">
var navLi = mainLeft.getElementsByTagName('a');
function hy() {
for (i = 0; i < navLi.length; i++) {
navLi[i].style.backgroundColor = "#FFF";
}
}
for (i = 0; i < navLi.length; i++) {
navLi[i].onclick = function() { hy(); this.style.backgroundColor = "#FF0"; }
}
</script>
温馨提示:答案为网友推荐,仅供参考