【问题标题】:Pop up modal immediately disappear弹出模态立即消失
【发布时间】:2021-04-24 10:42:37
【问题描述】:

enter image description here

图片显示表格中的数据。

我想要的是当我点击查看按钮时,它会弹出模态以显示该行数据。

我想获取该行数据并显示在弹出模式中。 我添加这个脚本后,模态框会直接弹出并关闭。 modal不能显示,modal只显示一秒直接关闭

脚本代码

$(document).ready(function() {
        $('.resetbtn').on('click', function() {
            $('#resetmodal').modal('show');
            $tr = $(this).closest('tr');
            var data = $tr.children("td").map(function() {
                return $(this).text();
            }).get();
            console.log(data);
            $('#pass_id').val(data[0]);
        });
    });

按钮代码

<button type="button" style="border:none; background-color: transparent;" data-toggle="modal" data-target="#resetmodal" class="resetbtn">view<i class="glyphicon glyphicon-asterisk" style="font-size:15px; color:blue;"></i></button> | 

模态代码

<div class="modal fade" id="resetmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h3 class="modal-title" id="exampleModalLabel"><b>RESET PASSWORD</b></h3>
            </div>
                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
                    <div class="modal-body">
                        <div class="form-group">
                            <input name="pass_id" id="pass_id" type="text" class="form-control" value="<?php echo $db_pass_id; ?>"></input>
                        </div>             
                        <div class="form-group">
                            <label><b>Password : </b></label> &nbsp;<span class="validation">*</span>
                            <input name="p_password3" id="p_password3" type="password" class="form-control input-box" onkeypress="return AvoidSpace(event)" onblur="this.value=removeSpaces(this.value);" minlength="6" required></input>
                            <input type="checkbox" onclick="myFunction3()">&nbsp; Show Password</input>   
                        </div>
                        <div class="form-group">
                            <label><b>Confirm Password : </b></label> &nbsp;<span class="validation">*</span>
                            <input name="p_password4" id="p_password4" type="password" class="form-control input-box" onkeypress="return AvoidSpace(event)" onblur="this.value=removeSpaces(this.value);" minlength="6" required></input>
                            <input type="checkbox" onclick="myFunction4()">&nbsp; Show Password</input>            
                        </div>                                  
                    </div>
                    <div class="modal-footer">
                        <button type="submit" name="reset" class="btn btn-primary">RESET</button>
                        <button type="button" name="close" class="btn btn-warning" data-dismiss="modal">CLOSE</button>
                    </div>
                </form>
        </div>
    </div>
</div>

【问题讨论】:

  • 它工作正常
  • 您是否尝试从按钮代码中删除“data-target="#resetmodal"”。
  • 删除 data-target="#resetmodal" 后,它的工作。谢谢,但为什么?
  • 您是否遇到任何控制台错误?

标签: php bootstrap-modal


【解决方案1】:

data-target="#resetmodal" 为您显示/隐藏!。但是在你的脚本里面你有

$('#resetmodal').modal('show');

换句话说,您使用该脚本显示模态并使用 data-target="#resetmodal" 隐藏

【讨论】:

    猜你喜欢
    • 2020-09-07
    • 1970-01-01
    • 2014-10-31
    • 2021-12-11
    • 2012-04-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2023-03-16
    相关资源
    最近更新 更多