twitter-bootstrap 如何使用 Bootstrap 模态对话框并获取返回值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30505287/
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
How I can use a Bootstrap Modal Dialog and get the return values?
提问by Tarasov
I want to create a Modal Dialog with Bootstrap. I am new in Bootstrap.
我想用 Bootstrap 创建一个模态对话框。我是 Bootstrap 的新手。
how this:
这是怎么回事:


How I can do this and how I get the values from the textfield back.
我如何做到这一点以及如何从文本字段中获取值。
回答by Alex
Modal is on the same page. So whatever input field you have inside modal is accessible in your page.
模态在同一页面上。因此,您可以在页面中访问模态内的任何输入字段。
For example you have
例如你有
<input type="text" id="txtName" />
You can simply access it using
您可以简单地使用它访问它
$("#txtName").val();
for Modal code. Here it is done
对于模态代码。到这里就完成了
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div id="myModal" 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">
<input type="text" id="txtname">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
回答by Har devgun
try this:
试试这个:
var name = $('#txtname').val();
for access value from dropdownlist:
对于下拉列表中的访问值:
You'd have something like:
你会有类似的东西:
var plantid = $('.drpplants').get(0).value;
Or
或者
var plantid = $('.drpplants').get(1).value;

