jQuery / Javascript确认两次出现

出于一些奇怪的原因,我得到了两次确认框。 这是我的代码:

$(".DeleteComment").live("click", function(){ var CommentID = $(this).attr("rel"); var confirm if (!confirm('Are you sure you want to permanently delete this comment?')){ return false; }else{ $(this).html("loading").css("color", "#999"); //AJAX HERE return false; } }); 

你是否动态加载任何内容(通过ajax)? 可能是click事件被绑定到同一元素两次导致双重确认的情况。

试试这个:

 $_blockDelete = false; $(".DeleteComment").live("click", function(event){ event.preventDefault(); //event.stopPropagation(); // it is not necessary if (!$_blockDelete) { $_blockDelete =true; var rconfirm = confirm('Are you sure you want to permanently delete this comment?'); if (rconfirm) { $(this).html("loading").css("color", "#999"); var CommentID = $(this).attr("rel"); //AJAX HERE //return the value "false" the variable "$_blockDelete" once again ajax response } } }); 

您是否尝试删除未使用的var confirm