开发者

Code works in Chrome but infinite loop in IE

开发者 https://www.devze.com 2023-03-20 22:08 出处:网络
I am using this code to dynamically change the text of a span element. It works in chrome, only changing the content of the span once, but does an in开发者_运维问答finite loop in IE (the count keeps u

I am using this code to dynamically change the text of a span element. It works in chrome, only changing the content of the span once, but does an in开发者_运维问答finite loop in IE (the count keeps updating and the html text keeps changing). Anyone know how I can fix it or why its happening?

bindFlagUpdate();
function bindFlagUpdate(){
    $(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
        var string = $('#like-' + data.contentId).html();
        var getNum = string.match(/[0-9]+/g);           
        var count = getNum[0];

        if(data.flagStatus == 'flagged') {
            count++;            
        } else {
            count--;        
        }           
        $('#like-' + data.contentId).html("1 user likes this");

        $(document).unbind();
        bindFlagUpdate();
        return false;
    });
}

Description of the event:

The flagGlobalAfterLinkUpdate event This event is triggered immediately after a flag link has been updated. (Flag links appear in two flavors: "Bookmark this!" and "Unbookmark this!", and when we speak of "update" we mean this change in appearance).

The even is attached to a "flag" button


To answer this we need to know more about the event flagGlobalAfterLinkUpdate and how it is triggered. It sounds like something in the callback function for the event is triggering the event, so once it's triggered once, it triggers itself continuously.

0

精彩评论

暂无评论...
验证码 换一张
取 消