首页 > 其他 > 详细

匿名函数和鼠标移入移除事件

时间:2017-06-21 12:46:45      阅读:242      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>改变边框</title>
    <style>
        .def {
            border: 1px solid #ccc;
            margin-right: 120px;
        }

        .hover {
            border: 1px solid red;
            margin-right: 120px;
        }
    </style>
    <script>
//        function over(target) {
//            target.className = ‘hover‘;
//        }
//        function def(target) {
//            target.className = ‘def‘;
//        }
        window.onload=function () {
            var img=document.getElementsByTagName(img);//取得所有的图片数组
            for(var i=0;i<img.length;i++){//遍历每一张图片
                img[i].onmouseover=function(){//每一张图片加一个onmouseover事件
                    this.className=hover;
                }
                img[i].onmouseout=function () {
                    this.className=def;
                }
            }
        }
        
    </script>
</head>
<body
">
<table>
    <tr>
        <td><img src="images/new_01.jpg" alt="" class="def"></td>
        <td><img src="images/new_02.jpg" alt="" class="def"></td>
        <td><img src="images/new_03.jpg" alt="" class="def"></td>
    </tr>
</table>
</body>
</html>

 

匿名函数和鼠标移入移除事件

原文:http://www.cnblogs.com/lwj820876312/p/7058550.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!