我试图在我的网站jQuery上放一个html php表单时遇到此错误

时间:2015-08-30 16:03:58

标签: jquery jquery-validate

我使用了相同的代码,数据与其他网站不同,它在本地和网上工作但是这个新网站不接受表单给我一个错误,任何人都可以帮忙吗?

HTML- 脚本:

   <script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<meta charset="utf-8">
<title>Untitled Document</title>

<script>
$(function() {
    $("#Message").validate({
        rules: {
            Name: {
                required: true,
                minlength: 2,
                maxlength: 15
                },
            Email: {
                required: true,
                email: true
                },
            Message: {
                required: true,
                minlength: 10
                 }
    }});

});
                </script>

形式:

<p><form id="Message" method="POST" action="message.php">
<p>Enter Name: <input id="Name" type="text" name="Name" size="20"></p>
<p>Enter Email: <input id="Email" type="text" name="Email" size="20"></p>
<p>Message: <input id="Message" type="text" name="Message" size"20"></p>
<p><input type="submit" value="Submit" name="Submit"></p> 

PHP Message.php:

<?php

## CONFIG ##

# LIST EMAIL ADDRESS
$recipient = "MYEMAIL";

# SUBJECT (Subscribe/Remove)
$subject = "WebMsg";

# RESULT PAGE
$location = "received.html";

## FORM VALUES ##

$sender = $recipient;

# MAIL BODY
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
$body .= "Message: ".$REQUEST['Message']." \n";
# add more fields here if required

## SEND MESSGAE ##

mail( $recipient, $subject, $body, "From: $sender" ) or header( "Location: $location" );

## SHOW RESULT PAGE ##

header( "Location: $location" );
?>

最后是控制台错误:

Uncaught TypeError: $(...).validate is not a function(anonymous function) @ index.html:15v.Callbacks.l @ jquery-1.8.3.min.js:2v.Callbacks.c.fireWith @ jquery-1.8.3.min.js:2v.extend.ready @ jquery-1.8.3.min.js:2A @ jquery-1.8.3.min.js:2

如果有人能回复并帮助我,我会非常感激,这对我来说很烦人

1 个答案:

答案 0 :(得分:1)

validate不是Jquery函数。您需要包含此内容才能使用验证方法:https://github.com/jzaefferer/jquery-validation

只需在Jquery之后包含它:

<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="jquery.validate.js"></script>