从Bootstrap模态对话框触发单击事件

时间:2016-01-22 21:44:07

标签: javascript jquery html bootstrap-modal

我正在尝试确定在点击以下代码中的“删除”按钮时如何触发事件。

<div aria-labelledby="myModalLabel" class="modal fade" id="removeUser"
    role="dialog" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body" id="window-border">
                    <div class="warning-text">
                        <h2>Remove User</h2>
                        <p>Are you sure you wish to remove this user?</p>
                    </div>
                    <div class="terminate">
                        <button class="btn btn-default close" data-dismiss=
                        "modal" type="button">Cancel</button> 
                        <button class=
                        "btn btn-default" id="confirm" type=
                        "submit">Remove</button>
                    </div>
                </div>
            </div><!-- end modal content -->
        </div>
    </div>

2 个答案:

答案 0 :(得分:1)

你可以点击jquery文件点击一个点击功能,如下所示:

$( document ).on( "click", "#confirm", function() {
   //your code here
});

答案 1 :(得分:0)

&#13;
&#13;
   //Indicate user the avaliable time period
    $('#confirm').click( function() {
      alert("removed");   
    });
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div aria-labelledby="myModalLabel" class="modal fade" id="removeUser"
    role="dialog" tabindex="-1">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body" id="window-border">
                    <div class="warning-text">
                        <h2>Remove User</h2>
                        <p>Are you sure you wish to remove this user?</p>
                    </div>
                    <div class="terminate">
                        <button class="btn btn-default close" data-dismiss=
                        "modal" type="button">Cancel</button> 
                        <button class=
                        "btn btn-default" id="confirm" type=
                        "submit">Remove</button>
                    </div>
                </div>
            </div><!-- end modal content -->
        </div>
    </div>
&#13;
&#13;
&#13;