faz*_*faz 4 javascript jquery twitter-bootstrap bootstrap-modal
当用户点击我的jQuery模式窗体上的取消按钮时,如何清除填充数据.
目前,当我点击取消按钮时,它只关闭弹出框,当我重新打开它时,仍然存储以前填充的数据.
请指教
<form id="myform2" data-toggle="validator" class="form-horizontal" role="form" method="POST" action="#">
<div class="form-group">
<div class="col-md-12">
<label class="control-label popup-label">Full Name</label>
<input required type="text" class="form-control" name="full_name"
value="{{ old('full_name') }}">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label class="control-label popup-label">Username</label>
<input required type="text" class="form-control" name="username"
value="{{ old('username') }}">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label class="control-label popup-label">Password</label>
<input pattern=".{5,10}" required title="5 to 10 characters"
type="password" class="form-control"
name="password" value="{{ old('password') }}">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Create</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel
</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我已经使用了bootstrap验证以及表单字段.
$(document).ready(function () {
$('#myform2').bootstrapValidator({
// To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
full_name: {
validators: {
notEmpty: {
message: 'The Full Name field is required'
},
stringLength: {
min: 5,
max: 15,
message: 'The Full Name must be more than 5 and less than 15 characters long'
},
Run Code Online (Sandbox Code Playgroud)
编辑
这是我的密码验证
password: {
validators: {
notEmpty: {
message: 'The Password field is required.'
},
stringLength: {
min: 5,
max: 15,
message: 'The Password must be more than 5 and less than 15 characters long'
}
}
}
Run Code Online (Sandbox Code Playgroud)
只需指定一个id="reset"取消按钮
<button type="button" class="btn btn-default" id="reset" data-dismiss="modal">Cancel</button>
Run Code Online (Sandbox Code Playgroud)
以下代码可以解决问题
$(document).ready(function() {
$("#reset").click(function() {
$("input").val("");
});
});
Run Code Online (Sandbox Code Playgroud)
或者更好的方法,使用表格 id="myform2"
$(document).ready(function() {
$("#reset").click(function() {
$(':input','#myform2').val("");
});
});
Run Code Online (Sandbox Code Playgroud)
要么
使用bootstrap验证插件,无需上述代码和取消按钮的任何更改,只需在引导验证脚本上方添加以下脚本即可.
$('#myModal').on('hidden.bs.modal', function(){
$(this).removeData('bs.modal');
$('#myform2').bootstrapValidator('resetForm', true);
});
$('#myform2').bootstrapValidator({
//Validation code comes here
});
Run Code Online (Sandbox Code Playgroud)
注意:这里我假设模态id #myModal如果不是你必须将它改为你的模态id,当模态关闭并重新打开时,这将使用取消按钮重置表单.
使用Bootstrap验证示例(自动复位输入,在模态加载时具有预加载值)
| 归档时间: |
|
| 查看次数: |
15801 次 |
| 最近记录: |