我有一個表單驗證編碼問題。我將發佈下面的代碼。基本上我希望表單提交如果cboAction是在另一個選擇。幫助jQuery驗證
cboAction有三個值,[選擇],插入和搜索。因此,如果在組合框中選擇了插入,那麼如果選擇了搜索,那麼表單應該使用jquery else進行驗證,然後表單應該被提交。我試圖在那裏放一個if語句,但它沒有奏效。 :(
者均基於表單驗證的作品,它只是我不能得到上述工作,希望從別人聽到。
感謝
jQuery.validator.addMethod(
"selectOption",
function(value, element) {
if(element.value == "nothing") {
return false;
} else {
return true;
}
},
"Please select an option."
);
$(document).ready(function() {
$("#authorForm").validate({
rules: {
cboAction: {selectOption:false}
txtName: {required:true},
txtStreet: {required:true}
txtTown: {required:true},
cboState: {selectOption:true},
txtPostcode: {required:true},
txtMobile: {required:true},
txtEmail: {required:true, email:true}
},
messages: {
cboAction: "Please select an action"
txtName: {required: "Author's Name is a required field"},
txtStreet: {required: "Street is a required field"}
txtTown: "Town is a required field",
cboState: "Please select a state",
txtPostcode: "Postcode is a required field",
txtMobile:
{
required: "Mobile is a required field",
email: "Please enter a valid email adress"
}
}
});
});
嗨,我把我的驗證碼之間的form.validate()。 – Mahie 2010-11-04 13:29:30
是的,在提交之前提交:false:{... – 2010-11-04 13:50:22
HALLELUJAH !!好極了。有效。謝謝哥們。 – Mahie 2010-11-04 14:39:18