【问题标题】:jQuery form validation showing Uncaught TypeError: Object [object Object] has no method 'validate'jQuery 表单验证显示 Uncaught TypeError: Object [object Object] has no method 'validate'
【发布时间】:2012-12-03 10:09:27
【问题描述】:

我正在使用 wordpress。在 wordpress 中,我想实时验证表单。所以在搜索了不同的 jQuery 表单验证后,我得到了 http://www.geektantra.com/projects/jquery-form-validate/ 链接。我使用了我网站中的所有源代码。但毕竟,当我呈现页面时,我的 chrome 控制台选项卡中出现了这个错误

Uncaught TypeError: Object [object Object] has no method 'validate' localhost:70
(anonymous function) localhost:70
o jquery.js:2
p.fireWith jquery.js:2
e.extend.ready jquery.js:2
c.addEventListener.B

我所有的 jquery 文件都包含在这样的头文件中

<?php
  wp_enqueue_script('jQuery', get_bloginfo('template_url').'/js/jquery-1.3.2.min.js');
  wp_enqueue_script('Validations', get_bloginfo('template_url').'/js/jquery.validate.js');
  wp_enqueue_script('Validations Function', get_bloginfo('template_url').'/js/jquery.validation.functions.js');
?>

head里面的jQuery代码是这样的

<script type="text/javascript">
 jQuery(document).ready(function() {
    jQuery("#ValidTitle").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "Please make a right selection for the title"
    });
    jQuery("#Name").validate({
        expression: "if (VAL) return true; else return false;",
        message: "Please enter your name"
    });
    jQuery("#BusinessPhone").validate({
        expression: "if (VAL.match(/^[9][0-9]{9}$/)) return true; else return false;",
        message: "Should be a valid Phone Number"
    });
    jQuery("#ValidEmail").validate({
        expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
        message: "Please enter a valid Email ID"
    });
    jQuery("#NumberOfEmployee").validate({
        expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
        message: "Please enter a valid number of employees"
    });
    jQuery("#ValueSoftware").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "Please make a right selection for Value Software"
    });                
    jQuery("#TaxYear").validate({
        expression: "if (VAL != '0') return true; else return false;",
        message: "Please make a selection"
    });
});

</script>

谁能帮我解决这个问题。这将是非常可观的。

【问题讨论】:

  • 你在JQuery之后包含了JS插件文件吗?
  • 也...许多 wordpress 页面最终会加载多个版本的 jQuerly。确保只有一个存在,并且在所有插件之前

标签: jquery jquery-plugins jquery-selectors


【解决方案1】:

通过查看您的错误代码,我认为可能存在一些问题,例如

  • jQuery 未正确加载到您的站点中

  • 在你的 jQuery 插件之后加载 jQuery 框架

所以要检查它们,只需通过页面源代码,即键盘中的ctrl+u,请检查每个文件是否与其外部文件正确链接。应该检查一个主要的事情是检查 jQuery 是第一次加载,然后是在你的 jQuery 插件加载之后。

希望这些步骤可以帮助您检查错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    相关资源
    最近更新 更多