我有以下代碼:setTimeout和時延不工作
var wait = 500;
$(document).on("click",".new_game_list_row",function(event){
var self = $(this);
//As the element clicked on has it's data attributes defined
//Retrieves it when the element is clicked on
var id_quiz_list = self.data('quizlistId'),
difficult = self.data('difficult');
userid = $("#new_game_list_wrap").data('userid');
setTimeout(function(){
$.post("new_game_add.php","userid="+userid+"&id_quiz_list="+id_quiz_list+"&difficult="+difficult,function(data){
$answer = data;
$("#new_game_list_wrap").fadeOut("slow",function(){
self.remove();
$("#quiz_list_wrap").append('<div class="quiz_list_row" data-quizlist-id="'+id_quiz_list+'" data-quizlevel-reached="0" '+
'><div class="inline list_cell" id="quiz_list_cell_rownew_id1">Quiz '+id_quiz_list+'</div><div '+
'class="inline list_cell" id="quiz_list_cell_rownew_id2">Current level: 1</div>');
showtrick(id_quiz_list,1);
});
}, "html");
}, wait);
});
我試圖用setTimeout()
以避免在該行多點擊。我的桌子上滿是幽靈條目。
我試過延遲,但它沒有工作。
有什麼想法?
背後的想法的例子。 http://jsfiddle.net/FszWw/17/ – Th3B0Y