首页 > 其他 > 详细

封装事件框架

时间:2019-09-28 22:45:04      阅读:109      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
<button id="btn">按钮</button>
<div id=div></div>
</body>
<script src=itcast.js></script>
<script type="text/javascript">

    //测试
    $$.event.click(btn, function(){
        document.getElementsByTagName(div)[0].style.background = green
    });

    $$.event.mouseover(div, function(){
        this.style.background = blue
    });

    $$.event.mouseout(div, function(){
        this.style.background = pink
    });

</script>
</html>

使用 extend 改造

$$.hover(‘div‘   ,   function(){  }  ,  function(){  } ) ;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background: red;
        }
    </style>
</head>
<body>
<button id="btn">按钮</button>
<div id=div></div>
</body>
<script src=‘itcast2.js‘></script>
<script type="text/javascript">

    //测试
    $$.click(btn, function(){
        document.getElementsByTagName(div)[0].style.background = green
    });

    $$.hover(‘div‘, function(){                    
        this.style.background = ‘blue‘
    },function(){
        this.style.background = ‘pink‘
    });

</script>
</html>

 

封装事件框架

原文:https://www.cnblogs.com/shanlu0000/p/11605191.html

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