2010-12-12 17 views
0

http://cl.ly/2D221O0J33421Y1v2V0QAJAX在Chrome中多次發佈

有沒有什麼辦法可以避免這種情況?

完全在Firefox等

votes.php:http://pastie.org/1369778

jQuery(function(){ 
jQuery("a.vote_down").click(function(){ 
//get the id 
the_id = $(this).attr('id'); 

// show the spinner 
$(this).parent().html("<img src='images/spinner.gif'/>"); 

//the main ajax request 
    $.ajax({ 
    type: "POST", 
    data: "action=vote_down&id="+$(this).attr("id"), 
    url: "/votes.php", 
    success: function(msg) 
    { 
    $("span#votes_count"+the_id).fadeOut(); 
    $("span#votes_count"+the_id).html(msg); 
    $("span#votes_count"+the_id).fadeIn(1000); 
    $("span#vote_buttons"+the_id).remove(); 
    } 
    }); 
}); 
}); 
+0

是這個問題什麼被張貼在下面 – kobe 2010-12-12 23:31:23

回答

2

你試過有你的點擊處理程序return false;(放置在函數的末尾,當然)?或者,嘗試在名爲e的處理程序中引入一個參數,然後添加e.stopPropagation();

底線是,你想阻止點擊事件冒泡一旦你處理它。

+0

這是行不通的。你能看看代碼嗎? http://pastie.org/1371658 – switz 2010-12-13 01:01:27

+0

是否有可能添加一段HTML代碼,並附帶此腳本,以便我可以看到標記是否與它有關,並嘗試重現自己? – HackedByChinese 2010-12-13 01:19:36

+0

我很困惑你的問題。如果你願意? – switz 2010-12-13 01:49:17

0

你可以更好的辦法嘗試使用「委託」方法而不是「點擊」快捷方式。 「$ .delegate」通過將事件分配給元素的上下文而不是窗口對象來防止事件「冒泡」。另外,如果您使用帶有空白「href」參數的「錨點」,則可以嘗試使用另一個HTML元素,例如跨度。