如何保存和关闭bootstrap模式? [英] How to save and close a bootstrap modal?
问题描述
这个问题有很多答案,但这些答案都没有解决我的问题。我有一个带有一些< select>
标签的模态。我试图保存选择选项
中的值。点击保存
之后,模式应该关闭但不会提交
结果,因为用户仍然需要在他们之后查看内容点击模式上的保存
。
This question have many answers out there but none of those answers solved my problem. I have a modal with some <select>
tags. I am trying to save the values from the select options
. after they click Save
the modal should close but not submit
the result yet because the user still need to review stuff after they click save
on the modal.
HTML
<!-- Modal -->
<div id="1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">× </button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
//select tags go here
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="save" onclick="save()" class="btn btn-width bkgrnd-cyan save-details" type="button" name="save-details">Save</button>
</div>
</div>
JS
$('#save').click(function() {
$('#1').modal('hide');
});
由于我的代码非常长,我只是从谷歌复制了一个模态,但我添加了保存
按钮,这是我的模态正在使用的真正的保存
按钮。
Since my code is really long, I just copied a modal from google but I added my Save
button, so this is the real Save
button that my modal is using.
谢谢
编辑
我将身份证号码更改为字母所以现在代码不包含任何以数字开头的id,谢谢。
I changed the id number to letters so now the code doesn't include any id starting with number, thanks.
PS仍然需要帮助= /
PS still need help =/
编辑
我也尝试了这个,它没有用。
I also tried this one and it did not work
$(document).ready(function(){
$('#save').click(function(){
$('#modal_1').modal('hide');//modal_1 is the id 1
});
});
推荐答案
我不确定 id = 1
没问题,但您可以使用此代码模拟关闭按钮上的点击(或者您可以为其添加ID或类)。
I'm not sure the id=1
is fine, but you can use this code to simulate a click on the close button (or you can add an id or a class to it).
您可能需要删除 onclick =save()
data = {};
$("#save").on("click", function(e){
e.preventDefault(); // prevent de default action, which is to submit
// save your value where you want
data.select = $("#exampleSelect").value();
// or call the save function here
// save();
$(this).prev().click();
});
这篇关于如何保存和关闭bootstrap模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!