인사말,최적화 jQuery 코드
그냥 (!) 모든 것이 완벽하게 작동, jQuery로 물건을 구축,하지만 난 가능한 한 optimzed대로 싶습니다 .. 작은 어떤 변화 내 코드를 할 수 있습니까?
$(document).ready(function() {
// hide the indicator, we use it later
$(".indicator").hide();
// start the animation of the progressbar
$(".fill").animate({ width: "50px",}, 4000, function() { $(".indicator").effect("pulsate", { times:999 }, 2000);});
// notify-me ajax function
$(".btn-submit").click(function() {
// get the variable email and put it in a new variable
var email = $("input#mail").val();
var dataString = 'mail='+email;
$.ajax({
type: "POST",
url: "/mail.php",
data: dataString,
dataType: "json",
success: function(msg){
// JSON return, lets do some magic
if(msg.status == "ok") {
$("#response-box").fadeIn("slow").delay(2000).fadeOut("slow");
$("#fade").fadeIn("slow").delay(2000).fadeOut("slow");
$("#response-box .inner").html("<h1>Thank you.</h1>We'll keep in touch!");
$("#mail").val("e.g. [email protected]ple.com");
} else {
$("#response-box").fadeIn("slow").delay(2000).fadeOut("slow");
$("#fade").fadeIn("slow").delay(2000).fadeOut("slow");
$("#response-box .inner").html("<h1>Oops.</h1>Please try again!");
}
}
});
//make sure the form doesn't post
return false;
});
});
+1 모든 포인트가 유효하며 불필요한 미세 최적화 팁이 없습니다. – galambalazs
그는'$ ('form_id')를 사용합니다. serialize()'? – ifaour
@ifaour 인코딩하려는 유일한 것이 전자 메일 주소이고 양식에 더 많은 것이있는 경우 성능 회귀가 될 수 있습니다. – lonesomeday