Bubbling the Dom of Jquery
My problem here I know is bubbling within the DOM because I have multiple pages inside of my pagination and when I click on a edit class link multiple times it bubbles and loads the same file continuously and I'm wanting to know a better way to solve this.
$('.edit').live('click', function(e) {
e.preventDefault();
var contentPageID = $(this).attr('id');
$('div.right_开发者_如何学Ccontent').load('modules/forms/edit/contentpages.php?contentPageID=' + contentPageID);
});
e.stopPropagation();
and
return false;
var b = 0;
$('.edit').live('click', function(e) {
e.preventDefault();
if(b==0){
var contentPageID = $(this).attr('id');
$('div.right_content').load('modules/forms/edit/contentpages.php?contentPageID=' + contentPageID);
}
b++;
});
To prevent multiple executions of the click
event, unbind
it after the first time:
$( '.edit' ).live( 'click', function(e) {
e.preventDefault();
var contentPageID = $(this).attr('id');
$( 'div.right_content').load('modules/forms/edit/contentpages.php?contentPageID=' + contentPageID);
$('.edit').unbind('click');
}
Try this
$('.edit').live('click', function(e) {
e.preventDefault();
var contentPageID = $(this).attr('id');
if($('div.right_content').data("currentPage") != contentPageID){
$('div.right_content').data("currentPage", contentPageID).load('modules/forms/edit/contentpages.php?contentPageID=' + contentPageID,
function(){
$('div.right_content').data("currentPage", null);
});
}
});
精彩评论