我遇到了jQuery驗證未在IE8中觸發的問題。所有其他瀏覽器都能正常工作。jQuery驗證和IE8
我創建這裏砍下例如:
http://www.gilkes.me.uk/jqueryvalidation/index.html
你可以看到,在IE9,火狐等,如果按鈕按下任一複選框取消選中顯示工具提示驗證消息。
在IE8中,不執行驗證。爲什麼是這樣?
形式標記:
<form action="http://www.google.com" method="post">
<div style="margin-top: 50px; text-align: left; margin-left: 30px;">
<ul>
<li style="list-style: none;">
<input class="checkbox" data-val="true" data-val-checkboxtrue="You must tick the box indicated." data-val-required="The QuestionAccepted field is required." id="Questions_0__QuestionAccepted" name="Questions[0].QuestionAccepted" type="checkbox" value="true" /><input name="Questions[0].QuestionAccepted" type="hidden" value="false" />
<strong>Question 1.</strong>
<input id="Questions_0__QuestionText" name="Questions[0].QuestionText" type="hidden" value="That you have been a United Kingdom resident for at least 6 out of the last 12 months." />
<input id="Questions_0__ValidationMessage" name="Questions[0].ValidationMessage" type="hidden" value="Please confirm that you have read and understood " />
<span class="field-validation-valid" data-valmsg-for="Questions[0].QuestionAccepted" data-valmsg-replace="true"></span></li>
<li style="list-style: none; margin-top: 30px;">
<input class="checkbox" data-val="true" data-val-checkboxtrue="You must tick the box indicated." data-val-required="The QuestionAccepted field is required." id="Questions_1__QuestionAccepted" name="Questions[1].QuestionAccepted" type="checkbox" value="true" /><input name="Questions[1].QuestionAccepted" type="hidden" value="false" />
<strong>Question 2.</strong>
<input id="Questions_1__QuestionText" name="Questions[1].QuestionText" type="hidden" value="That you are aged 74 or under." />
<input id="Questions_1__ValidationMessage" name="Questions[1].ValidationMessage" type="hidden" value="That you are aged 74 or under." />
<span class="field-validation-valid" data-valmsg-for="Questions[1].QuestionAccepted" data-valmsg-replace="true"></span></li>
</ul>
<p style="margin-top: 30px;">
<button type="submit" id="Continue" class="button-continue">
Buy Now
</button>
</p>
</div>
</form>
我覺得有可能是這個劇本的問題。在這個東西沒有用IE8 orrectly工作:
<script type="text/javascript">
jQuery.validator.unobtrusive.adapters.add("checkboxtrue", function (options) {
if (options.element.tagName.toUpperCase() == "INPUT" && options.element.type.toUpperCase() == "CHECKBOX") {
options.rules["required"] = true;
if (options.message) {
options.messages["required"] = options.message;
}
}
});
</script>
對不起。現在添加了相關的代碼。 – FloatLeft 2012-04-23 13:01:41