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

Posted 舞纷菲

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了控制元素的点击执行事件只执行一次相关的知识,希望对你有一定的参考价值。

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;
                }
            });

以上是关于控制元素的点击执行事件只执行一次的主要内容,如果未能解决你的问题,请参考以下文章