1

I am having a problem with a link that is appended to the page when a new message is available. It acts like a link when hovered over but fails to fire when clicked.

var data_split=data.split("*^*");
var count=$('.n_1').length;

if(parseInt(count)!=parseInt(data)) {
    var new_messages=parseInt(data)-parseInt(count);    
    if(new_messages!=0) {
        $('.message_update_holder').html(
            "<p><a class='center n_message' href='javascript:void(0);'>"
            +new_messages+" new notifications.</a></p>");
    }
} else {
    return;
}

To fire the click event my code is as follows

$(document).on('click', '.n_message', function(){
    get_notifications();
});

It should be noted that the first part of the code is loacted in a function that updates every 10 seconds. I have tried clearing the html from message_update_holder on every update but this did not seem to work.

4

2 回答 2

2

尝试改变这个:

 href='javascript:void(0);'

进入这个:

href='#something'

因为我认为javascript调用会导致功能障碍。

于 2012-12-01T11:46:45.597 回答
0
$('.n_message').live('click', function(){
    get_notifications();
});

你试试同样的live

于 2012-12-01T11:31:45.043 回答