我有这个模式
<form id="contactModal">
<div id="mymodal2" class="" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<span class="modal-title th2" id="lblModalLabel" name="lblModalLabel">Contact</span>
</div>
<div class="modal-body">
我想要的是每次关闭时清除模式,所以我写了一个像这样的脚本:
function clear() {
$("#txtNombreCompleto").val("");
$("#txtNombreEmpresa").val("");
$("#exampleInputEmail2").val("");
$("#dropOficina").val("");
$("#txtTelefono").val("");
$("#txtMensaje").val("");
}
$('#mymodal').on('hidden', function(){
$.clear(this)
});
所以我在模态中的输入是这样的:
<input type="text" class="form-control" id="txtNombreCompleto" name="txtNombreCompleto" placeholder="Nombre completo">
但是当我关闭模态时,它不会运行该函数,如何在模态关闭时运行该函数?问候
只需致电clear();
inside 引导模态hide.bs.modal事件(或hidden.bs.modal) http://getbootstrap.com/javascript/#modals-events处理程序或将函数设置为回调。也把你的代码放进去document ready handler https://learn.jquery.com/using-jquery-core/document-ready/用于在加载页面后附加事件处理程序。
$(document).ready(function() {
$('#mymodal').on('hidden', function() {
clear()
});
});
或获取模态内的所有元素并设置值
$(document).ready(function() {
$('#mymodal').on('hidden', function() {
$(':input', this).val('');
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)