javascript - 从模态 Bootstrap 调用操作

标签 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/

如何从模态 Bootstrap 调用操作?

那么,当点击模态 Bootstrap 中的“保存更改”按钮时,如何让系统调用操作 form2_action.php

非常感谢

最佳答案

  • 给你的表格一个id用于在 javaScript 代码中引用。

    <form id="form1">

  • 然后定义一个函数如下:

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

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

关于javascript - 从模态 Bootstrap 调用操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34259964/

相关文章:

javascript - 了解 'this' 在上下文中的功能

javascript - 将包含 contentEditable 的 html 元素移动到 dom 中的另一个分支而不失去焦点

jquery - 使用 span 使用 css 创建换行符

html - CSS flexbox 布局缩放滚动条错误

html - 需要帮助弄清楚为什么 border-radius 属性在表上不起作用

javascript - 如何在 reactjs 中包含外部 JavaScript 库

javascript - 当操作长度未知时定期运行操作

javascript - 单击关闭菜单/div 关闭

javascript - 使用数组值作为类型的流程

html - 将移动设备重定向到我网站的替代版本