我做這個簡單的jQuery腳本來檢查的形式對我來說...如何讓jquery只顯示正確的class div和ajax請求?
$(document).ready(function() {
$('.loading').hide();
});
function check_username(){
var username = $("#username").val();
$('.loading').show();
$.post("ajax.php", {
username: $('#username').val(),
}, function(response){
$('.info').fadeOut();
$('.loading').hide();
setTimeout("finishAjax('info', '"+escape(response)+"')", 450);
});
return false;
}
function check_email(){
var email = $("#email").val();
$('.loading').show();
$.post("ajax.php", {
email: $('#email').val(),
}, function(response){
$('.info').fadeOut();
$('.loading').hide();
setTimeout("finishAjax('info', '"+escape(response)+"')", 450);
});
return false;
}
function finishAjax(id, response){
$('.'+id).html(unescape(response));
$('.'+id).fadeIn(1000);
}
唯一的事情是,當有在後的用戶名錯誤在所有錯誤框的顯示錯誤,而不是一個分配給用戶名,無論如何要停止這一點,而不是分配所有的div來使用實用性的ID。
請不要將字符串傳遞給'setTimeout' - 你可以傳遞一個函數:'setTimeout(function(){finishAjax('info',response)},450);' – ThiefMaster