Javascript 我可以创建一个具有动态id的模态吗?
我一直在尝试创建一个模式窗口,该窗口以php生成的动态id打开。id都存储在数据库中,并在需要创建用户表时调用 我希望能够点击一个用户,并让他们的所有设置和选项显示在模式窗口中,尽管正如我上面所说,我希望有一个模式可以根据点击的用户为用户打开正确的信息 我有显示用户的当前代码:Javascript 我可以创建一个具有动态id的模态吗?,javascript,php,html,css,modal-dialog,Javascript,Php,Html,Css,Modal Dialog,我一直在尝试创建一个模式窗口,该窗口以php生成的动态id打开。id都存储在数据库中,并在需要创建用户表时调用 我希望能够点击一个用户,并让他们的所有设置和选项显示在模式窗口中,尽管正如我上面所说,我希望有一个模式可以根据点击的用户为用户打开正确的信息 我有显示用户的当前代码: if ($result->num_rows > 0) { echo " <table class='table table-hover'> <tr style='font-size:18
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";
我尝试了以下方法来打开模态
<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>
我对模式使用了错误的id吗?我认为您可以使用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);
});
});
});
和in process.php
您是否尝试过使用id$行[用户名]?我不认为id为id=something的div是有效的,我明白了,是的,我将尝试从您的id中删除=符号。另外,php是否呈现正确的id?是不是应该像IDI一样?你会一次打开多个动态ID的模态吗?一次打开一个模态,但是模态中的内容必须是动态的,我现在意识到,当我输入这个时,我可能刚刚找到问题的答案,可能已经把事情复杂化了!
//do whatever you need with the data
$id = $_POST['list'];
echo $id;