2

This is the first code

var operations = 0;
$('body').bind('DOMCharacterDataModified, DOMNodeInserted, DOMSubtreeModified', 'test', function() {
    if (operations < 1) {
        tba_highlight_numbers();
    }
    operations++;
});

And, here is the latest code of "tba_highlight_numbers" function.

function tba_highlight_numbers() {

//Highlighting the number on webpage.
$("body *:not(span.tba_phone)").replaceText(/\d*[/\(-]*[0-9][0-9][0-9][/ \)\(-]*[0-9][0-9][0-9][/ \)\(-]*[0-9][0-9][0-9][0-9][/ \) ]*/g, function(ss) {
    return '<span class="tba_phone" title="Make a Call to (' + $.trim(ss) + ') via ACT Browser Applet" style="color:green" rel="' + $.trim(ss) + '">' + ss + '</span>';
});

}

This js code performs an operation of highlighting the phone numbers on web page. But as you can see in first part, This function is called as many times data is modified on web page dynamically via ajax request and other methods.

So, My aim is to not perform operations on previously highlighted one.

Can somebody help me in achieving this.

4

1 回答 1

1

将函数更改为

function tba_highlight_numbers() {

    //Highlighting the number on webpage.
    $("body *:not(span.tba_phone)").filter(function(){ return $(this).hasClass(".already-hightlighted");}).replaceText(/\d*[/\(-]*[0-9][0-9][0-9][/ \)\(-]*[0-9][0-9][0-9][/ \)\(-]*[0-9][0-9][0-9][0-9][/ \) ]*/g, function(ss) {
        return '<span class="tba_phone" title="Make a Call to (' + $.trim(ss) + ') via ACT Browser Applet" style="color:green" rel="' + $.trim(ss) + '">' + ss + '</span>' + ss;
    });
    $("body *:not(span.tba_phone)").addClass('already-highlighted');


}
于 2013-05-22T03:20:17.343 回答