可能重复: jQuery custom validation method issuejQuery验证不工作的onchange
我有需要选择列表。它正在验证正常,但在更改选择值时不会删除错误消息。我不知道为什么,我之前使用过相同的代码,而没有这个问题。
的HTML:
<table border="0" cellspacing="0" cellpadding="0" class="menu">
<tr>
<form action="PHP/Nt6Subscribe.php" method="post" id="SinglePmnt">
<td width="211">
<select name="technology" class="select">
<option value="" selected="selected"> Please Select</option>
<option value="Interactive Brokers"> Interactive Brokers</option>
<option value="MB Trading"> MB Trading</option>
<option value="Patsystems"> Patsystems</option>
<option value="PFG"> PFG (Peregrine Financial)</option>
<option value="TD AMERITRADE"> TD AMERITRADE</option>
<option value="Trading Technologies"> Trading Technologies</option>
<option value="Vision Financial Markets"> Vision Financial Markets</option>
<option value="Hosted"> Zen-Fire</option>
</select>
</td>
<td width="189">Single Payment of $995</td>
<td width="211">
<input type="hidden" name="item_number" value="34">
<input type="submit" value="" class="orderNow" />
</td>
</form>
</tr>
</table>
的JavaScript代码:
<script type="text/javascript">
$(document).ready(function() {
var validator = $("#SinglePmnt").validate({
rules: {
technology: {
required: true
}
},
messages: {
technology: {
required: "Please select your broker technology"
}
},
errorElement: "span",
errorPlacement: function(error, element) {
error.appendTo(element.parent("td"));
}
});
});
</script>
综上所述,当你把它留在“请选择”,它没有价值,当你点击提交验证。如果您更改该值,则错误不会像应该那样消失。
我相信它通过名称属性,无论如何,我笑了,我添加了ID,它仍然不会删除错误消息onchange。 thx – 2010-09-29 21:08:45
嗯,也许它有一个问题,因为它的选择。我从来不是那个验证者的忠实粉丝。你可以尝试验证长度以确保它的长度大于0吗? – Ascherer 2010-09-29 21:12:17