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

控制元素的点击执行事件只执行一次

时间:2016-10-17 11:28:21      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:

if(e.handled !== true){ }
e.handled=true;
function(e)
 
 
 
完整例子:
$(‘.shoucangtitlele‘).click(function(e){
                if(e.handled !== true){
                    var data = $(this).attr(‘data‘);
                    alert(data);
                    if(data==‘on‘){
                        $(this).children(‘b‘).html(‘已收藏‘);
                        $(this).children(‘span‘).addClass(‘shoucanghou‘);
                        $(this).children(‘span‘).html(‘<i class="fa fa-star" aria-hidden="true"></i>‘);
                        $(this).attr(‘data‘,‘off‘);
                    }
                    if(data==‘off‘){                
                        $(this).children(‘b‘).html(‘收藏‘);
                        $(this).children(‘span‘).removeClass(‘shoucanghou‘);
                        $(this).children(‘span‘).html(‘<i class="fa fa-star-o" aria-hidden="true"></i>‘);
                        $(this).attr(‘data‘,‘on‘);
                    }
                e.handled=true;
                }
            });

控制元素的点击执行事件只执行一次

标签:

原文地址:http://www.cnblogs.com/mm2015/p/5968806.html

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