연락처 양식의 유효성을 검사하는 데 사용하는이 함수가 있지만 JSHint를 통해 실행할 때 "정의되지 않은"오류가 발생합니다. 나는 꽤 jquery 멍청 하네. 그리고 나는 이것들이 어떻게 정의되어 져야하는지 잘 모르겠다. - '필요'정의되지 않은 폼 데이터에서JSHint "정의되지 않음"오류
:
(function ($, document, undefined) {
$(document).ready(function(){
// Place ID's of all required fields here.
required = ["name", "email", "message"];
// If using an ID other than #email or #error then replace it here
email = $("#email");
errornotice = $("#error");
// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";
$("#theform").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
errornotice.fadeIn(750);
} else {
input.removeClass("needsfilled");
}
}
// Validate the e-mail.
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("needsfilled");
email.val(emailerror);
}
//if any inputs on the page have the class 'needsfilled' the form will not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
errornotice.hide();
return true;
}
});
// Clears any fields in the form when the user clicks on them
$(":input").focus(function(){
if ($(this).hasClass("needsfilled")) {
$(this).val("");
$(this).removeClass("needsfilled");
}
});
});
})(jQuery, document);
는 여기에 몇 가지 예입니다.
required = ["name", "email", "message"];
'i'는 정의되어 있지 않습니다.
for (i=0;i<required.length;i++) {
'이메일'이 정의되지 않았습니다.
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {