jQuery表单验证显示Uncaught TypeError:Object [object Object]没有方法'validate'

时间:2012-12-15 18:47:55

标签: jquery jquery-plugins jquery-selectors

我正在使用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>

有人可以帮助我解决这个问题。这将是非常可观的。

1 个答案:

答案 0 :(得分:0)

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

  • jQuery未在您的网站中正确加载

  • 在jQuery插件

  • 之后加载jQuery框架

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

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