Bootstrap Modal 中的 jQuery 验证不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27780533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery validation in Bootstrap Modal does not work
提问by Ricardo
Applying jQuery validation to a Modal bootstrap it has no effect , checked all the included libraries and their order and noticed that they were correct.
将 jQuery 验证应用于 Modal 引导程序没有效果,检查所有包含的库及其顺序并注意到它们是正确的。
- Bootstrap: version 3.3.1
- jQuery: version 1.11.1
- jQuery-validate: version 1.13.1
- 引导程序:版本 3.3.1
- jQuery:版本 1.11.1
- jQuery 验证:版本 1.13.1
Head Code:
头部代码:
<head>
<title>Titulo</title>
<link rel="stylesheet" type="text/css" href="../CSS/StyleSheet.css"/>
<script type="text/javascript" src="../Bootstrap/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../datepicker/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="../Jquery-Validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="../Javascript/ActionJS.js"></script>
<link rel="stylesheet" type="text/css" href="../Bootstrap/css/bootstrap.min.css" media="screen" />
<link rel="stylesheet" type="text/css" href="../datepicker/css/datepicker.css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
Modal code (Load it's HTML without AJAX)
模态代码(加载没有 AJAX 的 HTML)
<div class="modal fade" id="login_modal" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form class="form-horizontal" id="login-form" action="../PHP/ValidateForm.php" method="get">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title span7 text-center" id="myModalLabel"><span class="title">Login</span></h4>
</div>
<div class="modal-body">
<div class="col-md-6">
<div class="form-group">
<label for="input_email" class="control-label col-md-3">Your Email (login)</label>
<div class="col-md-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="input_password" class="control-label col-md-3">Password</label>
<div class="col-md-9">
<input type="password" class="form-control" id="pass" name="pass" placeholder="Password">
</div>
</div>
<div class="checkbox text-center">
<label><input type="checkbox" id="remember_me" name="remember_me">Remember me on this computer</label>
</div>
</div>
<div class="form-group text-center">
<div class="col-md-6 col-md-offset-3">
<button type="reset" class="btn btn-danger">Reset</button>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" name="login_form_submit" value="Login">Login</button>
</div>
</form>
</div>
</div>
</div>
Changing the tag into the modal -body submit button does not work and checked in this video would be the correct position it.
将标签更改为模态 -body submit 按钮不起作用,在此视频中检查将是正确的位置。
ActionJS Code (validation file)
ActionJS 代码(验证文件)
$(document).ready(function(){
$("#login-form").validate({
rules:{
name:{
required:true,
minLength:8
},
pass:"required"
},
messages:{
name:{
required:"Please provide your Login",
minLength:"Your Login must be at least 8 characters"
},
pass:"Please provide your password"
}
});
});
});
采纳答案by Sparky
Two problems with your code here...
你的代码有两个问题......
rules:{
name:{ // <- no such element
required:true,
minLength:8 // <- no such rule
},
pass:"required"
},
You have no such input element with
name="name"
. Perhaps you meantemail
.There is no such rule called
minLength
. I think you meantminlength
.
你没有这样的输入元素
name="name"
。也许你的意思是email
。没有这样的规则叫做
minLength
。我想你的意思是minlength
。
NOTE: You have the same two issues above also within your messages
option.
注意:您也可以messages
选择上述两个相同的问题。
Working DEMO: http://jsfiddle.net/nk3j4mtu/
工作演示:http: //jsfiddle.net/nk3j4mtu/