jQuery 验证无法在 iPhone 上运行

发布于 2025-01-08 11:52:58 字数 3137 浏览 5 评论 0原文

我已将活动监视器中的表单链接到移动网站,并使用 jQuery validate 进行验证。 一切在桌面浏览器上运行良好,但当我在 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>

I have linked a form from campaign monitor to a mobile site and I am using jQuery validate for validation.
All works well on desktop browsers but when I check on my Iphone the validations does not work.

I am not the experience using JQuery so any help would be much appreciated.

Thank you in advance!

Live Demo
http://files.perfectday.gb.com/internal/stackoverflow/mobile-form/get-your-coupon.php

My validation JQuery and form are as follows.

    <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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2025-01-15 11:52:58

我在使用 jQuery 版本 1.6.1+ 和验证插件版本 1.9 的 iPhone 上遇到了同样的问题

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

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

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

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

  form.submit()
}

I had the same issue on the iPhone with jQuery version 1.6.1+ and Validations plugin version 1.9

The workaround was to configure the plugin to not validate on form submit:

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

Validate the form and submit programmatically:

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

  form.submit()
}
纵情客 2025-01-15 11:52:58

(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);
    }
  }
});

(3 year later update): I've also found issues with with iPhones and jQuery.validate. Although the validation was applying, the first field was not scrolling into view. To get around this, I just updated my .invalidHandler() method to include:

$("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);
    }
  }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文