jQuery Validation插件在无效时复制提交时的错误

时间:2011-09-29 22:54:28

标签: jquery validation plugins

我已经试了好几个小时才能解决这个问题。我在我的表单上使用jQuery验证插件(v1.7)。除一个问题外,验证似乎正常工作。如果表单字段无效,则单击“提交”时会显示错误。

如果我再次单击“提交”,原始错误将保留,并在其下方添加另一个错误。实际上,我点击了提交10次,并且在页面上对该字段有10次相同的错误消息。

它就像脚本不工作onkeyup或者它只监视提交时的验证。

我的目标是拥有onkeyup检查验证规则。无论如何,我感谢任何帮助,并支持我目前的代码;

<script type="text/javascript" src="scripts/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="scripts/jquery/jquery-ui-1.8.9.custom.min.js"></script>
<script type="text/javascript" src="scripts/jquery/jquery.validate.min-1.7.js" charset="ISO-8859-1" /></script>
<script type="text/javascript" src="scripts/jquery/jquery.validate.additional-methods-1.7.js" /></script>


<script type="text/javascript">
$(function() {
$("#jerseyForm").validate({
    debug: true,
    rules: {
        name: "required",
        address: "required",
        city: "required",
        state: "required",
        zip: {
            required: true,
            digits: true
        },
        email: {
            required: true,
            email: true,
            onkeyup: true
        },
        phone: {
            required: true,
            phoneUS: true,
            onkeyup: true,
        }
    },
    messages: {
        name: "Please enter your name",
        address: "Please enter your address",
        city: "Please enter your city",
        state: "Please enter your state",
        zip: "Please enter your zip code",
        email: "Please enter a valid email address",
        phone: "Please enter a valid phone number"
         }                                           
});
});
</script>

<form id="jerseyForm" action="<?php echo $postURL;?>" method="post">
        <input type="hidden" name="subAction" value="send" />
<div id="customerDetails">
          <label for="name"><span class="required">*</span> Name</label>
          <input type="text" id="name" name="name" size="25" />

          <label for="address"><span class="required">*</span> Address</label>
          <input type="text" id="address" name="address" value="" size="25" />

          <br style="clear:both;" />

          <div style="float:left;"> 
          <label for="city"><span class="required">*</span> City</label>
          <input type="text" id="city" name="city" value="" size="15" />
          </div>
          <div style="float:left; margin-left:5px;">
          <label for="state"><span class="required">*</span> State</label>
          <input type="text" id="state" name="state" value="" size="5" />
          </div>
          <div style="float:left; margin-left:5px;">
          <label for="zip"><span class="required">*</span> Zip</label>
          <input type="text" id="zip" name="zip" value="" size="7" />
          </div>

          <br style="clear:both;" />

          <label for="phone"><span class="required">*</span> Phone</label>
          <input type="text" id="phone" name="phone" value="" size="25" />

          <label for="email"><span class="required">*</span> Email</label>
          <input type="text" id="email" name="email" value="" size="25" />
        </div>

    </div>

    <br style="clear:both;" />

  </div>

    <p><input type="submit" class="submit" name="send" value="Place Order" /> <input type="reset" class="reset" value="Start Over" /></p>

</form>

1 个答案:

答案 0 :(得分:0)

我已经测试了您的确切代码是Chrome,FireFox 3.x和MSIE 6(通过IETester)。我使用了jQuery 1.6.2和jQuery Validate 1.8.1,但我没有得到你看到的错误。但是我确实得到了与解析你的JSON相关的一个错误(仅在IE6中):

 phone: {
            required: true,
            phoneUS: true,
            onkeyup: true, // <--- this may be the culprit
        }

我知道我已经看到这个问题发生在多个同事身上。我认为额外的逗号可能是某些早期版本插件的问题。