我如何使用Bootstrap模态对话框并获取返回值?

时间:2022-06-26 06:39:59

I want to create a Modal Dialog with Bootstrap. I am new in Bootstrap.

我想用Bootstrap创建一个Modal对话框。我是Bootstrap的新手。

how this:

我如何使用Bootstrap模态对话框并获取返回值?

How I can do this and how I get the values from the textfield back.

我如何做到这一点以及如何从文本字段中获取值。

2 个解决方案

#1


3  

Modal is on the same page. So whatever input field you have inside modal is accessible in your page.

Modal在同一页面上。因此,无论您在模态中有什么输入字段都可以在页面中访问。

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">&times;</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


-1  

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;

#1


3  

Modal is on the same page. So whatever input field you have inside modal is accessible in your page.

Modal在同一页面上。因此,无论您在模态中有什么输入字段都可以在页面中访问。

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">&times;</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


-1  

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;