简体   繁体   English

在表格按钮内单击时不会出现弹出窗口

[英]Popup won't appear when clicked inside a table button

Can anyone suggest some alternative solution for this problem.任何人都可以为这个问题提出一些替代解决方案。

I've made a popup form which i use css and javascript to trigger the display to none or flex every time i click into a specific button which is great.我制作了一个弹出表单,我使用 css 和 javascript 每次点击特定按钮时触发显示为无或弯曲,这很棒。 But this method seems to not work on a table as you can see below i've done a simple query which i just fetch some of the essentials and included some buttons to use to trigger the popup form.但是这种方法似乎不适用于表格,正如您在下面看到的那样,我已经完成了一个简单的查询,我只是获取了一些必需品并包含一些用于触发弹出表单的按钮。

PHP/HTML CODE PHP/HTML 代码

                                <tbody>
                                    <?php
                                    $res=mysqli_query($link,"SELECT CONCAT(c.firstname, ' ', c.lastname) AS fullname, c.* FROM user_registration c");
                                    while($row=mysqli_fetch_array($res))
                                    {
                                            echo "<tr>";
                                            echo "<td>"; echo $row["id"]; echo "</td>";
                                            echo "<td>"; ?> <img src="<?php echo $row["image"]; ?>" height="100" width="100"> <?php echo "</td>";
                                            echo "<td>"; echo $row["fullname"]; echo "</td>";
                                            echo "<td>"; echo $row["username"]; echo "</td>";
                                            echo "<td>"; echo $row["id"]; echo "</td>";
                                            echo "<td>"; echo $row["id"]; echo "</td>";
                                            echo "<td>"; echo $row["id"]; echo "</td>";
                                            echo "<td>"; echo $row["id"]; echo "</td>";
                                            echo "<td>"; ?> <a href="#"><button class="btn btn-success" style="width: 100%">Accept</button></a><?php echo "</td>";
                                            echo "<td>"; ?> <a href="#" id="declineB"><button class="btn btn-danger" style="width: 100%">Decline</button></a><?php echo "</td>";
                                            echo "<td>"; ?> <a href="#"><button class="btn btn-success" style="width: 100%">View Message</button></a><?php echo "</td>";
                                            echo "</tr>";
                                    }
                                    ?> 
                                </tbody>

JAVASCRIPT CODE JAVASCRIPT 代码

document.getElementById("declineB").addEventListener("click", function(){
              document.querySelector(".popup3").style.display = "flex";
          })
          
          document.getElementById("closeDecB").addEventListener("click", function(){
              document.querySelector(".popup3").style.display = "none";
          })

When you have multiple elements with id declineB , document.getElementById("declineB") can actually only get the first element with id declineB .当您有多个 id declineB的元素时, document.getElementById("declineB")实际上只能获取第一个 id declineB的元素。 The effect you want will only appear when an element whose id is declineB .您想要的效果只会出现在 id 为的元素declineB When click others, no click event will be triggered.当点击其他人时,不会触发点击事件。

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

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