2012-04-23 62 views
1

我遇到了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> 
+0

对不起。现在添加了相关的代码。 – FloatLeft 2012-04-23 13:01:41

回答

1

这个问题是固定使用jQuery验证的1.9版本为我所用的版本(1.6)不使用jQuery的最新版本兼容:

jQuery Validation not working in IE7 + IE8

其实我读了这个问题但没有想到它适用于我,因为我确信我正在使用jQuery 1.9的版本验证

0

我还没有发现任何错误显示在提交的IE浏览器,所以我猜第一if声明没有返回true。您是否尝试过使用alert()来检查在IE8中有什么值options.element.tagNameoptions.element.type

+0

嗨,马丁,是的,我已经检查过,如果说明是返回true。 – FloatLeft 2012-04-23 13:19:17

+0

啊!刚刚意识到我正在使用jQuery验证的1.6版本,它与最新版本的jQuery不兼容 – FloatLeft 2012-04-23 13:34:41