jQuery验证不适用于Iphone

时间:2012-02-23 16:36:14

标签: jquery forms mobile jquery-validate

我已将广告系列监视器中的表单链接到移动网站,我正在使用jQuery验证进行验证。 一切都适用于桌面浏览器,但是当我检查我的Iphone时,验证不起作用。

我不是使用JQuery的经验,所以任何帮助都会非常感激。

提前谢谢!

现场演示 http://files.perfectday.gb.com/internal/stackoverflow/mobile-form/get-your-coupon.php

我的验证JQuery和表格如下。

    <script type="text/javascript">
    $.validator.methods.equal = function(value, element, param) {
        return value == param;
    };
    $(document).ready(function(){
    $("#subForm").validate({
            rules: {
                math: {
                    equal: <?php echo $randomNumTotal; ?>   
                }
            },
            messages: {
                math: "Try again!!"
            }
        });
    });
    </script>


<!-- Form -->
    <form action="http://perfectday.createsend.com/t/j/s/nyuyh/" method="post" id="subForm">

        <div class="name">
            <label for="name">Name:<span>*</span></label><br>
            <input type="text" name="cm-name" id="name" size="25" class="required text-input" />
        </div>
        <div class="nyuyh-nyuyh">
            <label for="nyuyh-nyuyh">Email Address:<span>*</span></label><br>
            <input type="text" name="cm-nyuyh-nyuyh" id="nyuyh-nyuyh" size="25" class="required email text-input"/>
        </div>
        <div class="address1">
            <label for="Address 1">Address 1:<span>*</span></label><br>
            <input type="text" name="cm-f-juar" id="Address1" size="25" class="required text-input" />
        </div>
        <div class="address2">
             <label for="Address 2">Address 2:<span>*</span></label><br>
            <input type="text" name="cm-f-juaj" id="Address2" size="25" class="text-input required" />
        </div>
        <div class="city">
            <label for="City">City/town:<span>*</span></label><br>
            <input type="text" name="cm-f-juat" id="City" size="25"class="required text-input" />
        </div>
        <div class="postal">
            <label for="postal">Post code:<span>*</span></label><br>
            <input type="text" name="cm-f-juai" id="postal" size="25"class="required text-input" />
        </div>
        <div class="captcha">
            Enter the correct result<span>*</span><br>
            <input type="text" name="captchaImage" id="sum"  value="<?php echo $randomNum ?> + <?php echo $randomNum2 ?>" disabled="disabled" />
            <input type="text" name="math" id="math" maxlength="6" />
        </div>
    <input value="submit information" class="submit" type="image" src="images/trans.png" class="get-your-coupon-submit" alt="Submit" >
    <br>
    </form>

2 个答案:

答案 0 :(得分:3)

我在iPhone上使用jQuery版本1.6.1+和Validations插件版本1.9

时遇到了同样的问题

解决方法是将插件配置为不对表单提交进行验证:

$("form").validate({
   onsubmit: false
});

验证表单并以编程方式提交:

if( $("form").valid() ){
  // post validation code

  form.submit()
}

答案 1 :(得分:2)

(3年后更新):我也发现了iPhone和jQuery.validate的问题。虽然验证正在应用,但第一个字段未滚动到视图中。为了解决这个问题,我刚刚更新了.invalidHandler()方法以包含:

$("foo").validate({
  invalidHandler: function(e, validator) {
    if(window.navigator.userAgent.match(/iphone/i)) {
      window.setTimeout(function() {
        $("html,body").animate({
          scrollTop: $(validator.errorList[0].element).offset().top
        });
      }, 0);
    }
  }
});