onmouseover為什么會自動執(zhí)行?????在測試的時候,onmouseover綁定的函數(shù)都會先執(zhí)行一遍,不是應(yīng)該鼠標(biāo)放上去再執(zhí)行嗎????????
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>tab切換 模仿</title>
<style type="text/css">
*{margin: 0;padding: 0;}
li{list-style: none;}
a{text-decoration: none;}
.wrapper{border: 1px solid #aaa;width: 250px;margin: 0 auto;position: relative;overflow: hidden;height: 100px;overflow: hidden;}
.tit{height: 30px;width: 258px;position: absolute;left: -1px;overflow: hidden;background-color: #eee;}
.tit a{display: block;line-height: 30px;background-color: #eee;
width: 50px;text-align: center;float: left;
color: #000;
margin-top: -1px;
border-bottom: 1px solid #aaa;
?}
.tit a:hover{background-color: #fff;color: orange;
border-left:1px solid #aaa;border-right:1px solid #aaa;
border-bottom: 1px solid #fff;}
.con{float: left;height: 70px;width: 250px; position: absolute;top:30px;}
.con .detail{display: none;float: left;padding: 10px;}
.con ul li{display: block;float: left;margin: 3px 7px;}
.show{display: block!important;}
</style>
</head>
<body>
<div>
<div id="tit">
<a href="">公告</a>
<a href="">規(guī)則</a>
<a href="">論壇</a>
<a href="">安全</a>
<a href="">公益</a>
</div>
<div id="con">
<ul ?class="detail">
<li>公告公告公告</li>
<li>公告公告公告</li>
<li>公告公告公告</li>
<li>公告公告公告</li>
</ul>
<ul ?class="detail ">
<li>規(guī)則規(guī)則規(guī)則</li>
<li>規(guī)則規(guī)則規(guī)則</li>
<li>規(guī)則規(guī)則規(guī)則</li>
<li>規(guī)則規(guī)則規(guī)則</li>
</ul>
<ul>
<li>論壇論壇論壇</li>
<li>論壇論壇論壇</li>
<li>論壇論壇論壇</li>
<li>論壇論壇論壇</li>
</ul>
<ul>
<li>安全安全安全</li>
<li>安全安全安全</li>
<li>安全安全安全</li>
<li>安全安全安全</li>
</ul>
<ul>
<li>公益公益公益</li>
<li>公益公益公益</li>
<li>公益公益公益</li>
<li>公益公益公益</li>
</ul>
</div>
</div>
</body>
</html>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
var tits=$("tit").getElementsByTagName('a');
var cons=$("con").getElementsByTagName('ul');
for (var i = 0; i < tits.length; i++) {
tits[i].onmouseover=tab(i);
};
function tab(i){
? alert(i);
}
</script>
2015-12-17
for (var i = 0; i < tits.length; i++) {
tits[i].onmouseover=tab(i);
};
這個地方不直接用使用方法名稱,使用下面的就可以了,
tits[i].onmouseover=function tab(i){
? alert(i);
};