【问题标题】:Jquery Validation Not Working with BootstrapJquery 验证不适用于 Bootstrap
【发布时间】:2013-07-16 04:07:53
【问题描述】:

您好,我正在使用 jquery 进行简单的表单注册验证。唯一的问题是我使用了引导框架。

当我点击注册按钮时会出现提示;

在火虫控制台中显示

[09:35:37.239] Empty string passed to getElementById(). @ http://www.matrimonyteam.com/home/registration

欲了解更多信息,请访问此网址 http://www.matrimonyteam.com/home/registration

function register(){

    var validator = $("#profileRegistrationForm").validate({
        rules: {                            
            firstName: "required",
            lastName: "required",
            email: "required",
            loginPassword: "required",
            mobileNumber: "required",       
            gender: "required",
            birthDate: "required",
            motherTongue: "required"
        },
        errorElement: "span",                               
            messages: {
            firstName: "Enter First Name",
            lastName: "Enter Last Name",
            email: "Enter Valid Email Address",
            loginPassword: "Enter Password",
            mobileNumber: "Enter Mobile Number",        
            gender: "Select Your Gender",
            birthDate: "Select Birth Date",
            motherTongue: "Select Mother Tongue"
            }
    });
    if(validator.form()){ 
         $('form#profileRegistrationForm').attr({action: '/home/saveprofile'});         
         $('form#profileRegistrationForm').submit();
    }   
}

点击事件被注册

 <script type="text/javascript"> 
    $(document).ready(function () {

        $('#register').click(function() {       
            register();
        });     
    </script> 

【问题讨论】:

  • 我之前看到过其他错误...screencast.com/t/XkwThGbcnio1
  • @SethMcClaine ,在 jquery 验证中添加了附加检查 $.browser && $.browser.msie .. 但理想情况下我不应该触及核心库......现在它可以工作了,谢谢

标签: jquery validation twitter-bootstrap jquery-validate


【解决方案1】:

我认为您在 jquery 1.9 之后使用的是较新版本的 jquery $.browser 已删除。

您可以downloadvalidate plugin的最新版本(当前版本:1.11.1)来解决问题。 或者您可以使用 CDN

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js

或从http://bassistance.de/jquery-plugins/jquery-plugin-validation下载

阅读jQuery.browser() removedjQuery Core 1.9 Upgrade Guide.

另请阅读this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多