日期:2014-05-16 浏览次数:20321 次
<script type="text/javascript"> function yanse(){ document.getElementById('picture').style.backgroundColor = '#f8f8f8'; document.getElementById('picture').style.border = '1px solid #00a2ff'; } function old(){ document.getElementById('picture').style.backgroundColor = '#f1f1f1'; document.getElementById('picture').style.border = '1px solid #D7D7D7'; } </script>
<ul class="photos clearfix"> <li> <div class="picture" id="picture" onMouseOver="yanse()" onMouseOut="old()"><span></span><a href="#"><img src="photo_1.jpg"></a></div> <div class="name"><a href="#">图片1</a></div> </li> <li> <div class="picture"><span></span><a href="#"><img src="photo_2.jpg"></a></div> <div class="name"><a href="#">图片2</a></div> </li> <li> <div class="picture"><span></span><a href="#"><img src="photo_3.jpg"></a></div> <div class="name"><a href="#">图片3</a></div> </li> <li> <div class="picture"><span></span><a href="#"><img src="photo_4.jpg"></a></div> <div class="name"><a href="#">图片4</a></div> </li> </ul>
<script type="text/javascript"> window.onload = function() { var ul = document.getElementsByTagName('ul'); for (var i = 0; i < ul.length; i ++) { if (ul[i].className.indexOf('photos') != -1) { var obj = ul[i].getElementsByTagName('div'); for (var j = 0;j < obj.length; j ++) { if (obj[j].className == 'picture') { obj[j].onmouseover = function() { this.style.backgroundColor = '#f8f8f8'; this.style.border = '1px solid #00a2ff'; } obj[j].onmouseout = function() { this.style.backgroundColor = '#f1f1f1'; this.style.border = '1px solid #D7D7D7'; } } } } } } </script>
------解决方案--------------------
<!DOCTYPE html> <html> <head> <title> new document </title> </head> <script type="text/javascript"> function yanse(obj){ obj.style.backgroundColor = '#f8f8f8'; obj.style.border = '1px solid #00a2ff'; } function old(obj){ obj.style.backgroundColor = '#f1f1f1'; obj.style.border = '1px solid #D7D7D7'; } </script> <body> <ul class="photos clearfix"> <li> <div class="picture" id="picture" onMouseOver="yanse(this)