87,993
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JSSample</title>
<style>
*{margin:0;padding: 0;}
ul{list-style:none;}
li{font-size: 80px;text-align: center;cursor: pointer;display: none;}
#main{width: 200px;margin:50px auto;
border: 10px solid black;
}
.li{width: 200px;height: 100px;line-height: 100px;background: gray;}
.li{width: 200px;height: 100px;line-height: 100px;background: gray;}
#main .set{display: block;background: red;}
.on .li{display: block;}
</style>
</head>
<body>
<div id="main">
<li id="li1" class="li set red">宝贝</li>
<li id="li2" class="li">商铺</li>
</div>
<script type="text/javascript">
function addEvent (id,event,fn) {
var ele = getDOM(id)||document;
if (ele.addEventListener){
ele.addEventListener(event,fn,false);
} else if(ele.attachEvent){
ele.attachEvent("on"+event,fn);
}
}
function getDOM (id) {
return document.getElementById(id);
}
var Clickflag = 0;
var oSet = document.getElementsByClassName("set")[0];
addEvent("main","mouseover",function () {
this.className = "on";
});
addEvent("main","mouseout",function () {
// if(!Clickflag){
this.className = "";
oSet.className = "li set";
// }
});
addEvent("li1","mouseover",function (event) {
this.className = "li set";
// getDOM("main").className = "on";
// event.stopPropagation();
});
addEvent("li1","mouseout",function (event) {
this.className = "li";
event.stopPropagation();
});
addEvent("li2","mouseover",function (event) {
this.className = "li set";
// getDOM("main").className = "on";
// event.stopPropagation();
});
addEvent("li2","mouseout",function (event) {
this.className = "li";
event.stopPropagation();
});
// addEvent("li2","click",function (event) {
// this.className = "li set";
// oSet = this;
// event.stopPropagation();
// getDOM("main").className ="";
// });
</script>
</body>
</html>
addEvent("main","mouseenter",function () {
this.className = "on";
});
addEvent("main","mouseleave",function () {
// if(!Clickflag){
this.className = "";
oSet.className = "li set";
// }
});
addEvent("li1","mouseenter",function (event) {
this.className = "li set";
// getDOM("main").className = "on";
// event.stopPropagation();
});
addEvent("li1","mouseleave",function (event) {
this.className = "li";
});
addEvent("li2","mouseenter",function (event) {
this.className = "li set";
// getDOM("main").className = "on";
// event.stopPropagation();
});
addEvent("li2","mouseleave",function (event) {
this.className = "li";
});