日期:2014-05-16 浏览次数:20474 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>Test</title> <style type="text/css"> ul{ list-style:none; } li{ background-image:url(Winter.jpg); width:100px; } </style> <script type="text/javascript"> var lis=document.getElementsByTagName("li"); for(var i=0;i<lis.length;i++){ lis[i].onmouseover=function(){ this.style.backgroundImage="url(Sunset.jpg)"; } lis[i].onmouseout=function(){ this.style.backgroundImage="url(Winter.jpg)"; } } </script> </head> <body> <ul> <li>aaa</li> <li>bbb</li> <li>ccc</li> </ul> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>Test</title> <style type="text/css"> ul{ list-style:none; } li{ background-image:url(Winter.jpg); width:100px; } </style> </head> <body> <ul> <li>aaa</li> <li>bbb</li> <li>ccc</li> </ul> <script type="text/javascript"> var lis=document.getElementsByTagName("li"); for(var i=0;i<lis.length;i++){ lis[i].onmouseover=function(){ this.style.backgroundImage="url(Sunset.jpg)"; } lis[i].onmouseout=function(){ this.style.backgroundImage="url(Winter.jpg)"; } } </script> </body> </html>
------解决方案--------------------
楼上正解
------解决方案--------------------
还可以
window.onload=funtion(){
var lis=document.getElementsByTagName("li");
for(var i=0;i<lis.length;i++){
lis[i].onmouseover=function(){
this.style.backgroundImage="url(Sunset.jpg)";
}
lis[i].onmouseout=function(){
this.style.backgroundImage="url(Winter.jpg)";
}
}
}