简体   繁体   English

在onClick中在history.go(-1)上打开Bootstrap Modal

[英]Open Bootstrap Modal on history.go(-1) in onClick

I have a bootstrap modal that needs to be opened when the user would want to go back to the previous page. 我有一个引导程序模式,当用户想要返回上一页时,需要打开该模式。 Basically the first step in the process is that a user would click a button and a modal will popup and then after entering values in the modal, the user would then want to proceed to the next step where another modal will appear to basically confirm what the user has entered on the previous modal. 基本上,该过程的第一步是用户将单击一个按钮,然后将弹出一个模态,然后在模态中输入值之后,用户将希望继续执行下一步,在此下一步中将出现另一个模态,以基本上确认用户已输入上一个模式。 If it happens that the user would want to change his/her answer, it can go back to the previous page and then update his/her answer. 如果碰巧用户想要更改他/她的答案,则可以返回到上一页,然后更新他/她的答案。 The problem in my code is that it can go back to the previous page but the modal isn't opening. 我的代码中的问题是它可以返回到上一页,但模式未打开。

HTML CODE ON THE FIRST PROCESS (FIRST MODAL): 第一步的HTML代码(第一模态):

<div class="modal fade bs-example-modal-lg" id="modal_insert" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
                <span aria-hidden="true">&times;</span>
                <span class="sr-only">Close</span>
            </button>
        <h4 class="modal-title" id="myModalLabel">Update Hearing Details</h4>
        </div>
            <form id="update_memo" class="form-horizontal form-label-left calender" name = "update_memo" enctype="multipart/form-data" method="post" role="form" novalidate>
                <div class="modal-body">
                    <div class="d item form-group">
                    <label class="col-sm-2 control-label">Hearing Number</label>
                        <div class="col-sm-8">
                            <input type="number" class="form-control" id="hearing_number" name="hearing_number" readonly="readonly"/>
                        </div>
                    </div>
                        <div class="d item form-group">
                            <label class="col-sm-2 control-label">Attendance<span class="required">*</span> </label>
                            <div class="col-sm-8" style = "margin-top: 7px;">

                                <input type="radio" id = "both_attendance"  name="attendance" value="2" checked > Both Parties Showed Up <br />
                                <input type="radio" id = "resp_attendance" name="attendance" value="0" > Respondent Did Not Show Up <br />
                                <input type="radio" id = "comp_attendance"  name="attendance" value="1" > Complainant Did Not Show Up <br />

                            </div>
                        </div>
                        <div class="m item form-group">
                            <label class="col-sm-2 control-label">Memo <span class="required">*</span></label>
                            <div class="col-sm-8">
                                <textarea rows="4" class="form-control" id="memo" name="memo" required="required"/></textarea>
                            </div>
                        </div>

                </div>
                <div class="modal-footer" style="margin:0;">
                    <button type="button" class="btn btn-default" data-dismiss="modal" style="margin-top: 4px;">Close</button>
                    <button id="send" type="submit" class="btn btn-success" name="update_memo">Save Record</button>
                </div>
            </form>
        </div>
    </div>
</div>

2ND MODAL: 第二模式:

<?php
include 'config.php';
if(isset($_POST['update_memo'])){
    $id = isset($_GET['id'])? $_GET['id'] : "";
    $hearingNo = $_POST['hearing_number'];
    $memo = $_POST['memo'];
    $attendance = $_POST['attendance'];

 ?>

<div class="modal fade bs-example-modal-lg" id="modal_confirm" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #f0ad4e; color:#fff">
                <h4 class="modal-title" id="myModalLabel">Memo Confirmation </h4>
            </div>
            <form id="update_memo" class="form-horizontal form-label-left calender" name = "update_memo" enctype="multipart/form-data" method="post" role="form" novalidate>
                <div class="modal-body" style="display:none">
                    <div class="d item form-group">
                        <label class="col-sm-2 control-label">Hearing Number</label>
                        <div class="col-sm-8">
                            <input type="number" class="form-control" id="h_num" name = "h_num" value="<?php echo $hearingNo; ?>" readonly="readonly"/>
                        </div>
                    </div>
                </div>              
                <div class=" item form-group">
                    <label class="control-label col-md-5 col-sm-5 col-xs-12" style="left:20px;" ><h4><b>Do you wish to continue with the memo?</b></h4></label>
                    <div class="col-sm-8"></div>
                </div>
                <div class=" item form-group">
                    <label class="control-label col-md-1 col-sm-1 col-xs-12"></label>
                    <div class="col-sm-10">
                        <blockquote style="font-size: 18px; right: 30px; text-align: justify"><?php echo $memo; ?></blockquote>
                    </div>
                </div>

                <div class="modal-footer" style="margin:0;">
                    <button type="button" style="margin-top: 6px;" class="btn btn-dark" name="return" onClick="javascript: history.go(-1); showModal(); ";><i class="fa fa-arrow-circle-o-left m-right"></i>  Return</button>
                    <button id="send" type="submit" class="btn btn-success" name="memo_confirm"><i class="fa fa-check m-right"></i>  Proceed</button>
                </div>
 <?php

  }
  ?>
            </form>
        </div>
    </div>
</div>

Javascript code to call the first modal: (it is like this because when the user clicks this it passes a value in data-id; this is working) 调用第一个模式的Javascript代码:(之所以这样,是因为当用户单击它时,它会在data-id中传递一个值;这是可行的)

$(document).ready(function(){
    $('#modal_insert').on('show.bs.modal', function (e) {
        var id = $(e.relatedTarget).data('id');
        //alert(id);
        $("#hearing_number").val(id);
});

2ND MODAL: 第二模式:

$(document).ready(function(){
    $('#modal_confirm').modal('show');
});

FUNCTION THAT TRIES TO CALL THE MODAL AFTER HISTORY.GO(-1) 尝试调用历史后的模态的功能.GO(-1)

        //not working
        $(document).ready(function(){
            function showModal() {  
            $('#modal_insert').modal('show');
            }
        });
        //alert("OPEN"); 

</script>

How can I achieve this? 我该如何实现? Which part of my code should be changed or tweaked? 我的代码的哪一部分应该更改或调整? Thank you so much in advance for your help!!! 提前非常感谢您的帮助!!!

When opening bootstrap modal change hash value of url. 打开引导程序模式时,更改url的哈希值。 Also trigger modal opening depending on hash 还根据散列触发模态开放

<script>
// use these codes inside $(document).ready...
$(_modal_id_).on('show.bs.modal', function (e) {
   window.location.hash = "open_modal";
})
if(window.location.hash == "#open_modal") { // edited: "open_model" to "#open_modal"
   var hash = window.location.hash;
   $(_modal_id_).modal('show');
}
</script>

So if user go one page back (eg http://domain.co/page.php#open_modal ) .modal('show') will trigger 因此,如果用户返回上一页(例如http://domain.co/page.php#open_modal ),则会触发.modal('show')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM