打印模态内容后,我的模态不会关闭

时间:2015-07-05 01:37:22

标签: javascript php html twitter-bootstrap

我打印模态主体后我的模态不会关闭但是我打印内容后仍然可以使用创建按钮和打印按钮 有谁可以帮助我?

这是我的模态代码,其中包含要打印的数据

<div class="modal fade" id="create" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"  >
    <div class="modal-dialog" padding="5px !important">
                       <!--/id for printing "div1" -->
        <div class="modal-content" >

            <div class="modal-header">
                <strong>
                <h4 class="modal-title">Create New User</h4>
                </strong>
            </div>
            <div class="modal-body"id="div1">
                <form method="POST" action="../process/create_new_user.php">
                    <div class="form-group">
                        <label for="exampleInputName2" >User Name</label>
                        <input type="text" class="form-control" id="exampleInputName2" pattern="^[a-zA-Z ]+$" title="Letters Only" placeholder="Student Name" NAME="newusername" required>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Password</label>
                        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" NAME="newuserpass" required>
                    </div>
                    <div class="checkbox text-right">
                        <label for="accounttype">Account Type</label>
                        <select name="securitylvl" id="accounttype" required>
                            <option value="" selected></option>
                            <option value="student">Student</option>
                            <option value="faculty">Faculty</option>
                            <option value="admin">Admin</option>
                            <option value="accounting">Accounting</option>
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary btn-sm" onclick="printContent('div1')">Print Content</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                        <button type="Submit" class="btn btn-primary">Create</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

这是我用来打印内容的脚本

<script>
    function printContent(el){
      var restorepage = document.body.innerHTML;
      var printcontent = document.getElementById(el).innerHTML;
      document.body.innerHTML = printcontent;
      window.print();
      document.body.innerHTML = restorepage;
    }
    </script>

1 个答案:

答案 0 :(得分:1)

我知道这是一年加旧但在脚本函数而不是

document.body.innerHTML = restorepage;

location.reload(true);