【问题标题】:jQuery plugin Validate: onfocusin doesn't worksjQuery 插件验证:onfocusin 不起作用
【发布时间】:2011-01-17 13:47:52
【问题描述】:

在这个名为 Validate 的著名 jQuery 插件中,有一个名为 'onfocusout' 的选项。但我想使用另一个名为 'onfocusin' 的文件,它没有记录但存在于代码中,并且插件的作者在回复中引用了它。

我一直在尝试的代码:

    <script type="text/javascript">
   $(document).ready(function() {
    $("form").validate({
     onsubmit: false,
     onkeyup: false, 
     onfocusin: true,
     onfocusout: false,
     rules: {
      nome: {
       required: true,
       minlength: 5
      }
     }
    })
   })
  </script>
 </head>
 <body>
  <form action="tutorial.php" method="post" enctype="text/plain" >
   <input type="text" name="nome" id="nome" />
   <button type="submit">Submit</button>
  </form>
 </body>

当我“关注”输入时,FireBug 会显示此错误消息:

validator.settings[eventType].call is not a function [Stop on this error] 
validator.settings[eventType] && v...eventType].call(validator, this[0] ); 
jquery...date.js (line 305)

现在,黄金问题:如何解决?

链接:

验证插件:

bassistance.de/jquery-plugins/jquery-plugin-validation/

验证文档,选项页面:

docs.jquery.com/Plugins/Validation/validate#toptions

验证插件代码:

ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.js

验证作者在 abouth onfocusin 上的回复:

groups.google.com/group/jquery-en/browse_thread/thread/652418e93c9618f1?pli=1

【问题讨论】:

  • 你想用它做什么?正如您在代码中看到的那样,它是一个函数..使用false 将覆盖它(禁用效果),否则您必须定义一个您想要做的函数。

标签: jquery plugins jquery-plugins validation


【解决方案1】:

代替 onfocusin: true,使用这个:

onfocusin: function(element) { $(element).valid(); }

这个错误我也遇到了同样的问题
validator.settings[eventType] &amp;&amp; ...eventType].call(validator, this[0] );

如果你想使用 onfocusout 使用相同的代码:

onfocusout: function(element) { $(element).valid(); }

希望对您有所帮助。

【讨论】:

    【解决方案2】:

    您不应使用“true”(布尔值)作为 onsubmit、onkeyup、onfocusin 和 onfocusout 参数的值。默认情况下,这些是函数(并且事件处于打开状态)。如果要关闭此事件,请将值设置为“false”或“undefined”(不带“)。 要了解验证插件,请查看源代码。文档不完整。 v1.9.

    【讨论】:

      猜你喜欢
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-05
      • 2012-11-13
      • 2017-03-31
      • 2015-07-03
      • 1970-01-01
      相关资源
      最近更新 更多