dousui3124 2018-09-04 00:18
浏览 57

HTML模式的问题,不显示

I had some troubles with some HTML modals. I made a query from a database and I want the result to be displayed with a modal in the front end.

Everything is good in the beginning when only the ID should be displayed in a button. But when I click on one, only the first one in the row opens, the rest of them are not corresponding.

As I know, when you want to show some more information about a specific ID, as in my situation couple more columns, that is possible with anchors <a> where the preferable information can be displayed through a new .php file and is selected from the others by the link.

Is there any way that I can do the same, maybe by specifying the ID in every button, then the right modal with the right information pops up?

Here is the code:

<?php while($row = mysqli_fetch_array($show)): ?> 
    <button>
        <h2>ID:</h2>
        <span>
            <?php echo $row['id']; ?>
        </span> 
    </button>

    <div class="modal-content">
        <div class="modal-header">
            <span class="close">&times;</span> 
            <h2>ΙD:</h2> 
            <span>
                <?php echo $row['id']; ?>
            </span> 
        </div> 

        <div class="modal-body"> 
            <ul> 
                <li>
                    <span>
                        <?php echo $row['name']; ?>
                    </span>
                </li> 
            </ul> 
        </div> 

        <div class="modal-footer">
            <?php echo $row['number']; ?>
        </div>
    </div> 
<?php endwhile; ?>

And the code for opening the modals:

var modal = document.getElementById('myModal');

var btn = document.getElementById("myBtn");

var span = document.getElementsByClassName("close")[0];

btn.onclick = function() {
    modal.style.display = "block";
}

span.onclick = function() {
    modal.style.display = "none";
}

window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
  • 写回答

1条回答 默认 最新

  • donglun1918 2018-09-04 02:51
    关注

    I think if you are using Bootstrap, you can use these codes below

    For the button to open modal:

    <button class="btn btn-success" data-toggle="modal" data-target="#try">Open Modal</button>
    

    Inside of the modal:

    <div class="modal fade" id="try" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <form id="form">
                <div class="row mt-4">
                    <div class="col-1"></div>
                    <div class="col-10">
                        <h3>Hi</h3>
                    </div>
                    <div class="col-1">
                        <button type="button" class="close mr-4" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div></div>          
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?