初學(xué)菜鳥,找不出問題,求大神告知為何沒有效果
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>水導(dǎo)航</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
ul{
list-style: none;
height: 50px;
border-bottom: 2px solid lightblue;
}
ul li{
float: left;
width: 120px;
margin:0 1px;
position: relative;
left: 20px;
}
a{
text-decoration: none;
display: inline-block;
width: 100%;
height: 50px;
line-height: 50px;
background: bisque;
text-align: center;
border-top-left-radius: 20px;
border-top-right-radius: 15px;
}
.on,a:hover{
background-color: palegreen;
color: white;
border-bottom: 2px solid red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var aA = document.getElementsByTagName(a);
for(var i=0;i<aA.length;i++){
? aA[i].onmouseover=function(){
? clearInterval(this.time);
? var This=this;
? setInterval(function{
? This.style.width=This.offsetWidth+8+"px";
? if (This.offsetWidth>=180) {
? clearInterval(This.time)
? }
? },30)
? }
? aA[i].onmouseout=function(){
? clearInterval(this.time);
? var This=this;
? setInterval(function{
? This.style.width=This.offsetWidth-8+"px";
? if (This.offsetWidth<=120) {
? this.style.width="120px";
? clearInterval(This.time)
? }
? },30)
? }
}
}
</script>
</head>
<body>
<ul>
<li><a class="on" href="#">Ke 聞</a></li>
<li><a href="http://idcbgp.cn/">直 播</a></li>
<li><a href="#">軍 事</a></li>
<li><a href="#">經(jīng) 濟(jì)</a></li>
<li><a href="#">國 際</a></li>
<li><a href="#">社 會</a></li>
</ul>
</body>
</html>
2017-11-06
setInterval(function{ 少了括號? 應(yīng)該是setInterval(function(){? ?,? 然后應(yīng)該是This.time=setInterval(function( ) { ,? ?document.getElementsByTagName(a); 括號里沒加引號應(yīng)該是document.getElementsByTagName(“a”);?
2017-10-19
第一,獲取a標(biāo)簽有引號,你沒有添加。第二,clearInterval(This.time),你有一次小寫了this。第三,設(shè)置的定時器前面是個變量(也就是This.time=setInterval),不然你怎么取消定時器.
2017-10-19
第一,獲取a標(biāo)簽有引號,你沒有添加。第二,clearInterVal(This.time),你兩次的不一樣。第三,設(shè)置的定時器前面是個變量(也就是This.time=setInterval),不然你怎么取消定時器.
2017-10-09
沒用啊,大神咋辦
2017-10-09
謝謝,我試試
2017-10-08
"setInterval(function{"這個function后面圓括號,“this.style.width="120px";”這里的this應(yīng)該是Tish