我的表單是通過使用JavaScript的鏈接提交的,但我也試圖驗證從justing jQuery驗證。鏈接提交時驗證不起作用,但如果將鏈接更改爲提交按鈕,驗證不起作用。我究竟做錯了什麼?由JavaScript提交的表單上的jQuery驗證
我的形式:
<form id="findmatch" method="post" action="search">
<div>
<label class="formlabel">Match Type
<input type="text" name="matchtype" id="matchtype" class="forminput" />
</label>
<label class="formlabel">Location (postcode)
<input type="text" name="location" id="location" class="forminput" />
</label>
<label class="formlabel">Radius (miles)
<input type="text" name="Radius" id="Radius" class="forminput" />
</label>
<label class="formlabel">Keywords
<input type="text" onblur="javascript:usePointFromPostcode(document.getElementById('location').value, showCompleteLatLng)" onchange="javascript:usePointFromPostcode(document.getElementById('location').value, showCompleteLatLng)" name="keywords" id="keywords" class="forminput" />
</label>
<input id="lat" class="hidden" name="lat" type="text" value="" />
<input id="lon" class="hidden" name="lon" type="text" value="" />
<a href="javascript:document.getElementById('findmatch').submit();" onmouseover="javascript:usePointFromPostcode(document.getElementById('location').value, showCompleteLatLng)" class="submit">Search</a>
</div>
</form>
我的jQuery是
<script type="text/javascript">
$(document).ready(function() {
$("#findmatch").validate({
rules: {
location: "required",
Radius: {
required: true,
digits: true
},
keywords: "required"
},
messages: {
location: "Please enter your postcode",
Radius: {
required: "Please enter a radius",
digits: "Please only enter numbers"
},
keywords: "Please enter the keywords you wish to search for"
}
});
});
</script>
'jQuery.valid ate()'有一個你可以設置的提交處理程序。也許這可能有幫助。 http://docs.jquery.com/Plugins/Validation/validate – dnagirl 2010-05-05 13:54:11
爲什麼你使用提交按鈕的鏈接呢?您應該使用它們打算使用的HTML元素。 – akamike 2010-05-05 13:58:07
更新了演示! – 2010-05-05 14:24:23