<!doctype html><html><head><meta charset="UTF-8"><title>Document</title><style type="text/css"> #div1{height: 490px;background-image: url(10.jpg);background-repeat:no-repeat;} li{width: 150px;height: 30px;list-style: none;background:white;margin: 15px;text-align: center;position: relative;top: 15px;left: -11px; line-height: 30px;opacity:0.8;border-radius:3px }</style><script src="move.js"></script><script type="text/javascript">window.onload=function(){ var oLi=document.getElementById('div1').document.getElementsByTagName('li')oLi.onmouseover=function(){ sartMove(oLi,{left:-21},function(){})}oLi.onmouseout=function(){ sartMove(oLi,{left:-11},function(){})}}</script></head><body><ul id='div1' ><li>横店</li><li>黄山</li><li>千岛湖</li><li>天目湖</li><li>安吉</li><li>大别山</li></ul></body></html>
1 回答
已采纳
stone310
TA贡献361条经验 获得超191个赞
//var oLi=document.getElementById('div1').document.getElementsByTagName('li') 这里中间的document多了 var oLi=document.getElementById('div1').getElementsByTagName('li') //这么写就行了 //获取到后需要遍历oLi,对具体的oLi使用事件 for (var i = 0; i < oLi.length; i++) { oLi[i].onmouseover = function () { sartMove(this, {left: -21}, function () { //这里使用this,表示当前触发事件的那一个li }) } oLi[i].onmouseout = function () { sartMove(this, {left: -11}, function () { }) } }
添加回答
举报
0/150
提交
取消