Javascript 如何在关闭时将引导模式重置为其原始内容?
另外,我的javascript不是很好,我知道有人问过这个问题,但解决方案不适用于我的问题,所以我会再次问这个问题 我被这个问题困住了,还没有找到解决办法。我想在模态结束后,把所有发生在模态中的事情都清除掉 我的模式是一个表单模式,因此每当我单击submit时,codeigniter验证消息将通过使用Javascript 如何在关闭时将引导模式重置为其原始内容?,javascript,jquery,twitter-bootstrap,bootstrap-modal,Javascript,Jquery,Twitter Bootstrap,Bootstrap Modal,另外,我的javascript不是很好,我知道有人问过这个问题,但解决方案不适用于我的问题,所以我会再次问这个问题 我被这个问题困住了,还没有找到解决办法。我想在模态结束后,把所有发生在模态中的事情都清除掉 我的模式是一个表单模式,因此每当我单击submit时,codeigniter验证消息将通过使用上的ajax显示。现在,每当我关闭模式时,当我重新打开它时,验证消息保持不变。关闭模式后,应采取什么措施清除这些障碍 这是ajax调用的函数: public function addcomp ()
上的ajax显示。现在,每当我关闭模式时,当我重新打开它时,验证消息保持不变。关闭模式后,应采取什么措施清除这些障碍
这是ajax调用的函数:
public function addcomp () {
$this->load->library('form_validation');
$this->load->helper('security');
$this->form_validation->set_rules('comp_name','Computer Name','trim|required|callback_pc_exist');
$this->form_validation->set_rules('status','Status','trim|required');
$this->form_validation->set_rules('location','Location','trim|required');
if ($this->form_validation->run()) {
$this->load->model('asset_model');
$result=$this->asset_model->addpc();
if (!$result) {
echo mysqli_error($result);
} else {
echo "<div class='alert alert-success alert-dismissable'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
Computer Successfully Added!</div>";
}
}
echo validation_errors("<div class='alert alert-danger alert-dismissable'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>","</div>");
}
你可以利用。您应该关注以下两个方面:
调用hide实例方法后,立即触发此事件hide.bs.modal
当对用户隐藏模式完成时,将触发此事件(将等待CSS转换完成)hidden.bs.modal
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find("#info").html(""); // Just clear the contents.
$(this).find("#info").remove(); // Remove from DOM.
});
});
更新
查看代码时,您可能需要使用以下方法:
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find(".alert-danger").remove(); // Remove from DOM.
});
});
你可以利用。您应该关注以下两个方面:
调用hide实例方法后,立即触发此事件hide.bs.modal
当对用户隐藏模式完成时,将触发此事件(将等待CSS转换完成)hidden.bs.modal
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find("#info").html(""); // Just clear the contents.
$(this).find("#info").remove(); // Remove from DOM.
});
});
更新
查看代码时,您可能需要使用以下方法:
$(function () {
// Delegating to `document` just in case.
$(document).on("hidden.bs.modal", "#myModalID", function () {
$(this).find(".alert-danger").remove(); // Remove from DOM.
});
});
如何添加验证消息?有什么特别的吗?@PraveenKumar编辑了我的帖子是的,选中了。请核对我的答案。将
#info
替换为.alert error
或任何需要删除的类。更新的答案对您有帮助吗,伙计?您如何添加验证消息?有什么特别的吗?@PraveenKumar编辑了我的帖子是的,选中了。请核对我的答案。将#info
替换为.alert error
或任何需要删除的类。更新的答案对你有帮助吗,伙计?@GuruprasadRao Ha。请参阅OP的帖子:$(“#addpc”)[0].reset()代码>。对不起,Praveen。。我想他会要求对每个字段进行字段验证,并希望删除这些字段。所以重置表单是更好的选择,对吗?@GuruprasadRao这看起来像是服务器端的硬编码验证。如果我回答的话,我现在就会失去声誉了皮亚。。只要读到他把所有这些都放在一个div
中就可以了。。您的解决方案应该有效…:)@古鲁帕萨德罗哈哈哈。请参阅OP的帖子:$(“#addpc”)[0].reset()代码>。对不起,Praveen。。我想他会要求对每个字段进行字段验证,并希望删除这些字段。所以重置表单是更好的选择,对吗?@GuruprasadRao这看起来像是服务器端的硬编码验证。如果我回答的话,我现在就会失去声誉了皮亚。。只要读到他把所有这些都放在一个div
中就可以了。。您的解决方案应该有效…:)