cdn在jquery中不起作用

时间:2014-07-10 07:21:41

标签: jquery

我在php中使用jquery validation.i创建注册页面。我正在使用CDN(内容传送网络)进行执行jquery。当我运行程序时它不会工作验证部分(jquery部分)如果我是点击提交按钮页面将重定向下一页.jquery没有验证。是什么原因?回答我 我的代码在这里

<html>
    <head><title>sign up</title> 
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
    <script>
       $(document).ready(function(){
            $("#signup").validate({
                rules:
                    {
                    name : "required",
                    username :"required",
                   password : {required : true,minlength : 5,maxlength :10},
                    rpassword : 
                        {
                        required : true,
                        equalTo : "#password"
                        },
                   email_id: {required: true,email: true}
                    },
             messages:
                {
              name : "please provide your name",
              username : "please provide your username",
              password : {required : "please enter your password",minlenth : "your password must be atleast  5 character ",maxlength : "your password must be with in 10 character"},
              rpassword : {required : "please enter your confirmation password", equalTo : "Enter Retype Password Same as Password"},
              email_id: {required : "please enter e-mail id" ,email:"Please enter valid email"}
                },
                  submitHandler : function(form)
                  {
                   submitHandlerform.submit();   
                  }
               });
            });
            </script>
    </head>
    <body>
        <form id="signup" action="signup.php" method="post" >
            <h1> REGISTRATION </h1>
            <table>
    <tr>
        <td align="right">
            <h2><b>full name</td></h2>
            <td align="left"><input type="text" name="name"></b></tr>
            <tr>
<td align="right">
    <h2> <b>username</td></h2>
            <td align="left"><input type="text" name="username" ></b></tr>
<td align="right">
       <h2> <b>password</td></h2>
<td align="left"><input type="password" name="password" id="password" ></b></td>
<tr>
<td align="right">
       <h2> <b>confirmation password</td></h2>
<td align="left"><input type="password" name="rpassword" ></b></td>

    </tr>        
    <td align="right"><h2><b>email id</td></h2>
<td align="left"><input type="text" name="email_id" ></b></td></h2>
    </tr>
    <tr>
            <td align="right"><input type="submit" name="submit"> </td>    </tr>
            </table>
        </form>
        you have already account click <a href="index.php">here</a>
    </body>
</html>

2 个答案:

答案 0 :(得分:1)

在jquery下添加验证插件,如

<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.0/jquery.validate.min.js"></script>

为了您的信息,jquery validate插件适用于jquery 1.6。所以更新你的jquery

答案 1 :(得分:1)

试试这个。它的工作:

<html>
    <head><title>sign up</title> 
   <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
    <script>
       $(document).ready(function(){
            //$('#signup').submit( function(){
              $("#signup").validate({
      rules:
          {
          name : "required",
          username :"required",
        password : {required : true,minlength : 5,maxlength :10},
          rpassword : 
              {
              required : true,
              equalTo : "#password"
              },
        email_id: {required: true,email: true}
          },
              messages:
      {
    name : "please provide your name",
    username : "please provide your username",
    password : {required : "please enter your password",minlenth : "your password must be atleast  5 character ",maxlength : "your password must be with in 10 character"},
    rpassword : {required : "please enter your confirmation password", equalTo : "Enter Retype Password Same as Password"},
    email_id: {required : "please enter e-mail id" ,email:"Please enter valid email"}
      },
        submitHandler : function(form)
        {
        submitHandlerform.submit();   
        }
    });
            //});
          });
            </script>
    </head>
    <body>
        <form id="signup" action="signup.php" method="post" >
            <h1> REGISTRATION </h1>
            <table>
    <tr>
        <td align="right">
            <h2><b>full name</td></h2>
            <td align="left"><input type="text" name="name"></b></tr>
            <tr>
<td align="right">
    <h2> <b>username</td></h2>
            <td align="left"><input type="text" name="username" ></b></tr>
<td align="right">
       <h2> <b>password</td></h2>
<td align="left"><input type="password" name="password" id="password" ></b></td>
<tr>
<td align="right">
       <h2> <b>confirmation password</td></h2>
<td align="left"><input type="password" name="rpassword" ></b></td>

    </tr>        
    <td align="right"><h2><b>email id</td></h2>
<td align="left"><input type="text" name="email_id" ></b></td></h2>
    </tr>
    <tr>
            <td align="right"><input type="submit" name="submit"> </td>    </tr>
            </table>
        </form>
        you have already account click <a href="index.php">here</a>
    </body>
</html>