简体   繁体   English

jquery.validation不适用于IE和智能手机的低音

[英]jquery.validation not working on IE and smartphone bassistance

I'm using bassistance jquery.validation and it works on ff and chrome but not on mobile and IE. 我正在使用bassistance jquery.validation,它适用于ff和chrome,但不适用于移动和IE。 The examples on the website works fine but once in my project only ff and chrome. 网站上的示例工作正常,但在我的项目中只有ff和chrome。 I'm using ruby and rails. 我正在使用红宝石和铁轨。

Using this setup . 使用此设置

(function() {
// use custom tooltip; disable animations for now to work around lack of refresh method on tooltip
$("#madlibs_form").tooltip({
    show: false,
    hide: false
});


// validate signup form on keyup and submit
$("#madlibs_form").validate({
    rules: {
        industry: {
            required:"required";
        },
        amount: {
            required:"required";
        }


    },
    messages: {
        desired_amount: {
            required:{"Please enter loan amount"}

    }
});

$("#madlibs_form input:not(:submit)").addClass("ui-widget-content");
$(":submit").button();
})();

I'm not understanding how your code works in any browser at all... 我根本不了解您的代码在任何浏览器中的工作原理......

required:"required";
  • Setting required rule to "required" breaks the rule and it's ignored. required规则设置为"required"会破坏规则并将其忽略。
  • Using a semicolon prevents the plugin from working at all. 使用分号可以防止插件工作。

Should be this... 应该是......

required: true

Also, check how you placed braces around your custom messages. 另外,请检查您在自定义消息周围放置大括号的方式。

DEMO: http://jsfiddle.net/Lks8E/ 演示: http//jsfiddle.net/Lks8E/


Alternatively, you could do it like this. 或者,你可以这样做。 Notice how we use the field name in this case and they are separated with a comma. 请注意我们在这种情况下如何使用字段名称,并用逗号分隔。

industry: "required",
amount: "required"

DEMO 2: http://jsfiddle.net/Lks8E/1/ 演示2: http//jsfiddle.net/Lks8E/1/


EDIT based on OP's comment: 编辑基于OP的评论:

This is how my html looks <input type="text" name="desired_amount" class="madlibs_enter_amount" placeholder="enter a amount" required > should I add required="true" here? 这就是我的html看起来<input type="text" name="desired_amount" class="madlibs_enter_amount" placeholder="enter a amount" required >我应该在这里添加required="true"吗?

This explains why your code was working in some browsers. 这解释了为什么您的代码在某些浏览器中运行。 Since you had required within the input element, HTML 5 validation took over where the plugin was failing. 既然你已经required在中input元素,HTML 5的验证接手其中的插件是失败。

No. you alreay have a required attribute in there, why would you also add another one... required="true" ? 不,你在那里有一个required attribute ,为什么你还要添加另一个... required="true" Although, it might be best to replace it with proper HTML 5 syntax, required="required" . 虽然,最好用适当的HTML 5语法替换它, required="required" See: https://stackoverflow.com/a/3012975/594235 请参阅: https//stackoverflow.com/a/3012975/594235

And since you already have the required attribute within the HTML, you don't need to redundantly declare any of those required rules within .validate() . 由于您已经在HTML中拥有了required attribute ,因此您无需在.validate()冗余地声明任何required规则。

$('#madlibs_form').validate();

Examine this jsFiddle very carefully... 仔细检查这个jsFiddle ...

http://jsfiddle.net/PFF4v/ http://jsfiddle.net/PFF4v/

Fix issue jquery validate + jquery (1.4.4 ) don't working IE 7: 修复问题jquery validate + jquery(1.4.4)不工作IE 7:

Don't use : 不要使用:

$('#form').validate({
 rules : {
  name : "required"
 }
});

use : 采用 :

$('#form').validate({
 rules : {
  name : {
   required : true
  }
 }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM