這裏驗證表單是我的代碼:使用jQuery.click不起作用
$('input#price_match_submit').click(function(event) {
if ($.trim($('input#price_match_competitor_price').val()) == '') {
alert("Please enter competitor's price.");
return false;
}
if ($.trim($('input#price_match_name').val()) == '') {
alert("Please enter your name.");
return false;
}
if ($.trim($('input#price_match_quantity').val()) == '') {
alert("Please enter the quantity.");
return false;
}
if ($.trim($('input#price_match_email').val()) == '') {
alert("Please enter your email address.");
return false;
}
if ($.trim($('input#price_match_competitor_website').val()) == '') {
alert("Please enter competitor's website.");
return false;
}
if ($.trim($('input#price_match_phone_number').val()) == '') {
alert("Please enter your phone number.");
return false;
}
});
這裏#price_match_submit
是一個提交按鈕。當我點擊按鈕時,這個函數應該執行並驗證表單。但它沒有按照我的預期工作。該表格未經任何驗證即被提交。我在哪裏做錯了?
請顯示您的'HTML',以便我們可以測試它。小提琴將幫助我們解決您的問題。 –
你可以請發佈按鈕代碼? –
點擊功能將無法正常工作,因爲它不會阻止默認提交。所以使用提交而不是點擊。 – Rajiv007