码迷,mamicode.com
首页 > 其他好文 > 详细

事件中嵌套事件而出现的事件累积!

时间:2015-06-28 22:47:17      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="js/jquery-172.js"></script>
    <style>
            .demo1{width: 50px;height: 50px;margin-left: 20px;background: #c20;float: left; cursor: pointer;}
    </style>
</head>
<body>
    <div class="demo1"></div>
    <script>
            $(function (){
                $(.demo1).on(mouseenter,function (){
                            console.log(mouseenter);

                            $(this).on(click,function (){            //第移入一次div红块随后点击一下,开始出现一次click,随后2次,三次....
                                    console.log(click);                        //每次移入div就追加一次click事件。导致事件累积
                            });

                            //可以这样
                            /*$(this).off(click).on(click,function (){
                                    console.log(click);                    //这样就可以解决事件累积   原理是什么?为什么会这样?我也想知道  ^_^...    
                            });*/
                });
            });
    </script>
</body>
</html>

 

事件中嵌套事件而出现的事件累积!

标签:

原文地址:http://www.cnblogs.com/ctm58/p/4606148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!