html> <html lang="en"> <head> <meta charset="UTF-8"> <title>图片列表:鼠标移入移出改变图片透明度title> <style> div { border: 1px solid #000; width: 720px; padding: 10px 10px; margin: 0 auto; } img { border: 1px solid darkgrey; margin: 5px 5px; cursor: crosshair; opacity: 0.5; } style> <script> var aa = document.getElementsByTagName('img'); window.onload = function() { for (var i=0;i<aa.length;i++) { console.log(aa.length); aa[i].onmouseover = function() { this.style.opacity = 1; }; aa[i].onmouseout = function() { this.style.opacity=""; } } } script> head> <body> <div> <img src="BMW.jpg" /> <img src="alfo romeo.jpg" /> <img src="skoda.jpg" /> <img src="大众.jpg" /> <img src="saab.jpg" /> <img src="兰博基尼.jpg" /> <img src="保时捷.jpg" /> <img src="标致.jpg" /> <img src="奔驰.jpg" /> <img src="别克.jpg" /> div> body>