【问题标题】:How I can use a Bootstrap Modal Dialog and get the return values?如何使用引导模式对话框并获取返回值?
【发布时间】:2023-03-30 17:54:01
【问题描述】:
我想用 Bootstrap 创建一个模态对话框。我是 Bootstrap 的新手。
这是怎么回事:
我如何做到这一点以及如何从文本字段中获取值。
【问题讨论】:
标签:
javascript
jquery
html
twitter-bootstrap
dialog
【解决方案1】:
模态在同一页面上。因此,您可以在页面中访问模态框内的任何输入字段。
例如你有
<input type="text" id="txtName" />
您可以简单地使用它访问它
$("#txtName").val();
用于模态代码。到这里就完成了
<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>
【解决方案2】:
试试这个:
var name = $('#txtname').val();
从下拉列表中访问值:
你会有类似的东西:
var plantid = $('.drpplants').get(0).value;
或者
var plantid = $('.drpplants').get(1).value;