gpt4 book ai didi

jquery - Bootstrap 验证不起作用

转载 作者:行者123 更新时间:2023-12-01 00:56:29 26 4
gpt4 key购买 nike

我正在尝试使用 bootstrap 进行验证。我尝试了解决方案 here但它不起作用。

<form id="tryitForm" class="form-horizontal">
<div class="form-group">
<label class="col-md-3 control-label">Full name</label>
<div class="col-md-4">
<input type="text" class="form-control" name="firstName" />
</div>
<div class="col-md-4">
<input type="text" class="form-control" name="lastName" />
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label">Email address</label>
<div class="col-md-6">
<input type="text" class="form-control" name="email" />
</div>
</div>

<div class="form-group">
<label class="col-md-3 control-label">Gender</label>
<div class="col-md-6">
<div class="radio">
<label><input type="radio" name="gender" value="male" /> Male</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="female" /> Female</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="other" /> Other</label>
</div>
</div>
</div>

<div class="form-group">
<div class="col-md-offset-3 col-md-8">
<button type="submit" class="btn btn-primary">Say hello</button>
</div>
</div>
</form>

我已经添加了正确的js文件,请参阅fiddle link 。请帮助了解问题所在。

最佳答案

这是一个工作中的jsfiddle:http://jsfiddle.net/P28nR/1/

缺少或不正确的内容是:

  • 您没有包含 jquery
  • 您添加了错误的 jquery bootstrap 插件。正确的文件可以在以下链接中找到:

//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/css/bootstrapvalidator.min.css//cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.4.5/js/bootstrapvalidator.min.js

  • 您没有添加 JavaScript 来配置和运行验证器插件

    $(document).ready(function() {
    $('#tryitForm').bootstrapValidator({
    feedbackIcons: {
    valid: 'glyphicon glyphicon-ok',
    invalid: 'glyphicon glyphicon-remove',
    validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
    firstName: {
    validators: {
    notEmpty: {
    message: 'The first name is required and cannot be empty'
    }
    }
    },
    lastName: {
    validators: {
    notEmpty: {
    message: 'The last name is required and cannot be empty'
    }
    }
    },
    email: {
    validators: {
    notEmpty: {
    message: 'The email address is required'
    },
    emailAddress: {
    message: 'The input is not a valid email address'
    }
    }
    },
    gender: {
    validators: {
    notEmpty: {
    message: 'The gender is required'
    }
    }
    }
    },
    submitHandler: function(validator, form, submitButton) {
    var fullName = [validator.getFieldElements('firstName').val(),
    validator.getFieldElements('lastName').val()].join(' ');
    alert('Hello ' + fullName);
    }
    });
    });

关于jquery - Bootstrap 验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com