简体   繁体   English

我可以使用动态ID创建模态吗?

[英]Can I create a modal with a dynamic id?

I have been trying for a while now to create a modal window that opens with dynamic id's that are generated in php. 我已经尝试了一段时间来创建一个模态窗口,打开时使用php生成的动态id。 The id's are all stored within a database and called when needed to create a user table. id都存储在数据库中,并在需要时调用以创建用户表。

I want to be able to click on a user and have all of their settings and options appear in the modal window, although as I have said above I want one modal that opens the correct information for the user depending upon which users has been clicked. 我希望能够点击一个用户并让他们的所有设置和选项出现在模态窗口中,尽管如上所述,我想要一个模式,根据点击的用户打开用户的正确信息。

I have the current code displaying the users: 我有显示用户的当前代码:

if ($result->num_rows > 0) { echo "
<table class='table table-hover'>
  <tr style='font-size:18px;'>
    <th>Name</th>
    <th>Username</th>
  </tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "
  <tr style='font-size:16px;'>
    <td><a href=\ "#id=$row[username]\">".$row["name"]."</a>
    </td>
    <td style='color:#3c9bce'>".$row["username"]."</td>
  </tr>"; } echo "</table>"; } else { echo "There are 0 clients in the system matching your search criteria";

and I have tried the following to get the modal to open. 我已经尝试了以下方法来打开模态。

<div id="#id=$row[username]">
  <div class="modal-content">
    <div class="header">
      <h4 style="text-align: center;">Use the map below to select the closest agent to the breakdown</h4>
    </div>
    <div class="copy">
      <p>THIS IS A MODAL</p>
    </div>
    <div class="cf footer">
    </div>
  </div>
  <div class="overlay"></div>
</div>

Am I using the wrong id for the modal? 我使用错误的id作为模态吗?

I think you can solve this using a bit of jQuery/Ajax. 我想你可以使用一些jQuery / Ajax来解决这个问题。

$(function() {
     $(document).on("click", "#editData", function () {
     var list = $(this).attr("data-id");
        $('#containerData').html('');  
        $.post("process.php",{list:list},
            function(data){
                $('#containerData').html(data);
             });

         });
     });

and in process.php 并在process.php

//do whatever you need with the data
$id = $_POST['list'];
echo $id;

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

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