下拉列表小例子

来源:互联网 发布:爰淘宝 编辑:程序博客网 时间:2024/06/05 06:55

<!DOCTYPE html>

<html>

<head>

<metacharset="UTF-8">

<title></title>

<styletype="text/css">

ul{

display:none;

list-style:none;

margin:0;

padding:0;

text-align: center;

width:100px;

}


</style>

</head>

<body>

<divid="wrap">

<divid="title">

春雨今晚翻谁的牌子?

</div>

<ulid="down_list">

<li>日韩</li>

<li>欧美</li>

<li>保加利亚</li>

<li>尼日利亚</li>

<li>克罗地亚</li>

</ul>

</div>

<scripttype="text/javascript">

varoWrap = document.getElementById("wrap");

var aLists = document.getElementsByTagName("li");

var oDownList = document.getElementById("down_list");


oWrap.onmouseover= function (){

oDownList.style.display= "block";

}

oWrap.onmouseout= function (){

oDownList.style.display= "none";

}

// aLists[0].onmouseover = function (){

// for (var i = 0; i < aLists.length; i++) {

// aLists[i].style.backgroundColor = "";

// }

// aLists[0].style.backgroundColor = "yellow";

// }

// aLists[1].onmouseover = function (){

// for (var i = 0; i < aLists.length; i++) {

// aLists[i].style.backgroundColor = "";

// }

// aLists[1].style.backgroundColor = "yellow";

// }

// aLists[2].onmouseover = function (){

// for (var i = 0; i < aLists.length; i++) {

// aLists[i].style.backgroundColor = "";

// }

// aLists[2].style.backgroundColor = "yellow";

// }

// aLists[3].onmouseover = function (){

// for (var i = 0; i < aLists.length; i++) {

// aLists[i].style.backgroundColor = "";

// }

// aLists[3].style.backgroundColor = "yellow";

// }

// aLists[4].onmouseover = function (){

// for (var i = 0; i < aLists.length; i++) {

// aLists[i].style.backgroundColor = "";

// }

// aLists[4].style.backgroundColor = "yellow";

// }

// this关键字:事件绑定时,在事件内,指代被绑定的对象

for(var i = 0; i< aLists.length; i++) {

aLists[i].onmouseover= function (){

this.style.backgroundColor= "yellow";

}

aLists[i].onmouseout= function (){

this.style.backgroundColor= "";

}

}


</script>

</body>

</html>

0 0
原创粉丝点击