简体   繁体   English

为什么我的Jquery Validate无法正常工作?

[英]Why isn't my Jquery Validate working?

I have done some online research and can not find a solution. 我已经做了一些在线研究,找不到解决方案。 I am using the Jquery Validator plug in to validate my log in and registration forms. 我正在使用Jquery Validator插件来验证我的登录和注册表格。 I have coded my registration form and it works exactly as it should. 我已经对注册表格进行了编码,它完全可以正常工作。 However I coded my log in the same exact way and it does not work. 但是,我以完全相同的方式对日志进行编码,因此无法正常工作。 When I have blank fields, no message is displayed and the form is allowed to be submitted. 当我有空白字段时,不显示任何消息,并且允许提交表单。

Sign-in.php 登录

<html>
<head>
 <link type="text/css" rel="stylesheet" href="../skin/frontend/css/styles.css" media="all"> 
 <?php include('../js/jquery.js'); ?>
 <script src="//code.jquery.com/jquery-1.10.2.js"></script>
 <script src="../js/validator.js"></script>
 <script src="../js/sign-in.js"></script>
</head>
<body>
    <div class="wrapper">
        <div class="header"><?php include('../app/views/frontend/header.php'); ?></div>
        <div class="body-container">
                Sign in <br>
                <form method="post" action="../account/signin/sign-in.php" id="signin"> 
                <input type ='text'placeholder='Username' name="usernamesignin" id="usernamesignin" ><br>
                <br>
                <input type='text' onfocus="this.type='password'" placeholder='Password' name="passwordsignin" id="passwordsignin"><br>
                <br>
                <input type="submit" value="Log In">
                </form>
                </div>
    </div>  
    </body>
</html>  

Sign-in.js Sign.in

$(document).ready(function(){
 $("#signin").validate({
  rules: {
     usernamesignin: {
        required: true
           },
           passwordsignin:{
         required: true,
         minlength:6
         }
            },
           messages: {
                 username: {
        required: "Please Enter A Username"
           }
  }
     });
     });

Am I missing something? 我想念什么吗? This should be pretty simple. 这应该很简单。

Also I notice in my console.log that my registration page throws no errors, however my signin page shows: "Uncaught TypeError: Cannot read property 'msie' of undefined" 另外,我在console.log中注意到,我的注册页面未引发任何错误,但是我的登录页面显示:“未捕获的TypeError:无法读取未定义的属性'msie'”

Not sure if that is the issue. 不知道这是否是问题。

Thanks in advance! 提前致谢!

Got it! 得到它了! Type in form action and form id.. Problem solved! 输入表单操作和表单ID。问题已解决!

I've got your validation by doing the following: 通过执行以下操作,我得到了您的验证:

  1. Remove the line "<?php include('../js/jquery.js'); ?>" . 删除行"<?php include('../js/jquery.js'); ?>" You shouldn't have two references to jQuery 您不应有两个对jQuery的引用
  2. Edit the following line to be <script src="https://code.jquery.com/jquery-1.10.2.js"></script> . 将以下行编辑为<script src="https://code.jquery.com/jquery-1.10.2.js"></script> You are missing the protocol https: 您缺少协议https:

As per the this question , you should be able to define a URI without a protocol, but in this instance, when linking to the code.jquery.com CDN, it does not work. 按照这个问题 ,您应该能够在没有协议的情况下定义URI,但是在这种情况下,当链接到code.jquery.com CDN时,它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM