从模态引导程序

时间:2015-12-14 04:48:51

标签: javascript jquery html css twitter-bootstrap

我的HTML代码是这样的:

<form action="form2_action.php" method="post">
    <table>
        <tr>
            <td>First Name </td>
            <td>:</td>
            <td><input type="text" id="first_name" name="first_name" required></td>
        </tr>
        <tr>
            <td>Last Name</td>
            <td>:</td>
            <td><input type="text" id="last_name" name="last_name" required></td>
        </tr>
        <tr>
            <td>Age</td>
            <td>:</td>
            <td><input type="text" id="age" name="age" required></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td><input type="submit" value="Submit" id="submit"></td>
        </tr>
    </table>
</form> 


<div class="modal fade" id="confirm-save" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel"><b>Are you sure to book this tour?</b></h4>
            </div>

            <div class="modal-body">
                <table style="width:100%">
                    <tr>
                        <td style="width:30%">First Name</td>
                        <td height top="40" style="width:70%" id="first_name_modal"></td>
                    </tr>
                    <tr>
                        <td>Last Name</td>
                        <td height="40" id="last_name_modal"></td>
                    </tr>
                    <tr>
                        <td>Age</td>
                        <td height="40" id="age_modal"></td>
                    </tr>                 
                </table>        

                <p class="debug-url"></p>
            </div>

            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Save changes</button>&nbsp;
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>  
            </div>
        </div>
    </div>
</div>

我的Javascript代码是这样的:

$('#submit').on('click',function(e){

        var first_name_modal = document.getElementById("first_name").value;
        var last_name_modal = document.getElementById("last_name").value;
        var age_modal = document.getElementById("age").value;

        if(first_name_modal!="" && last_name_modal!="" && age_modal!=""){
            $("#confirm-save").modal("show");
            $('#first_name_modal').text(first_name_modal);
            $('#last_name_modal').text(last_name_modal);
            $('#age_modal').text(age_modal);
          return false;
        }
    });

演示是这样的:http://jsfiddle.net/oscar11/xxx03c6z/

如何从模态引导程序调用操作?

因此,当点击模态引导程序中的“保存更改”按钮时,如何让系统调用操作form2_action.php

非常感谢

3 个答案:

答案 0 :(得分:0)

  • 为表单添加id,以便在javaScript代码中进行引用。

    <form id="form1">

  • 然后定义如下函数:

    function formSubmit(){
       $('#form1').submit();
    }
    
  • 点击“保存”按钮调用formSubmit

    <button type="button" onClick="formSubmit();" class="btn btn-primary">

答案 1 :(得分:0)

  1. 表格提交

    $( “#模态提交-BTN”)。点击(函数(){    $( '模式 - 对话框-ID')模态( '隐藏')。    $( '#形式的ID')提交(); });

答案 2 :(得分:0)

检查我的脚本它工作正常..只需将表单标签置于引导程序模式并从输入值获取值到bootstap模型。这是小提琴,您可以查看:https://jsfiddle.net/kriz1439/v5wpwcv9/

<table>
    <tr>
        <td>First Name </td>
        <td>:</td>
        <td><input type="text" id="first_name" name="first_name" required>          </td>
    </tr>
     <tr>
        <td>Last Name</td>
        <td>:</td>
        <td><input type="text" id="last_name" name="last_name" required></td>
    </tr>
    <tr>
        <td>Age</td>
        <td>:</td>
        <td><input type="text" id="age" name="age" required></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td><button type="button" id="submit" class="btn btn-info btn-lg" data-toggle="modal" data-target="#confirm-save">Submit</button></td>
    </tr>
</table>



       <div class="modal fade" id="confirm-save" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-dialog">
    <div class="modal-content">
    <form action ="action.php">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel"><b>Are you sure to book this tour?</b></h4>
        </div>

        <div class="modal-body">
            <table style="width:100%">
                <tr>
                    <td style="width:30%">First Name</td>

                 <td height top="40" style="width:70%"  >  <input type="text" id ="first_name_modal"></td> 
                </tr>
                <tr>
                    <td>Last Name</td>

                     <td height="40" > <input type="text" id ="last_name_modal"> </td>
                </tr>
                <tr>
                    <td>Age</td>

                     <td height="40">  <input type="text" id ="age_modal"> </td>
                </tr>                 
            </table>        

            <p class="debug-url"></p>
        </div>

        <div class="modal-footer">
           <input type="submit" /> &nbsp;
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>  
        </div>
     </div>
     </div>
     </div>
  </form>

   </body>
      <script>
          $('#submit').on('click',function(e){

   document.getElementById("first_name_modal").value = document.getElementById("first_name").value;
    document.getElementById("last_name_modal").value= document.getElementById("last_name").value;
     document.getElementById("age_modal").value = document.getElementById("age").value;

    if(first_name_modal!="" && last_name_modal!="" && age_modal!=""){
        $("#confirm-save").modal("show");
        $('#first_name_modal').text(first_name_modal);
        $('#last_name_modal').text(last_name_modal);
        $('#age_modal').text(age_modal);
           return false;
              }
               });
     </script>