如何使用php动态地将id传递给弹出窗口?我需要自动将id值增加到弹出窗口.Plz帮我解决这个问题。
include("config.php");
$query=mysql_query("select * from reports_form");
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
$job_detail1 = $row['job_description']; ?>
<script>
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}</script>
<td align="center"> <div class="popup" onclick="myFunction()">
<a href="#myPopup<?php echo $id; ?>"> Click me!</a>
<span class="popuptext" id="myPopup"><?php echo "$job_detail1";?> </span>
</div></td>
</tr>
<?php
}
?>
答案 0 :(得分:1)
首先,你不应该在循环中使用你的脚本,并且传递你的函数变量它应该在
之下?>
<script>
function myFunction(id) {
var popup = document.getElementById("myPopup");
console.log(id)
popup.classList.toggle("show");
}
</script>
<?php
include("config.php");
$query=mysql_query("select * from reports_form");
while($row=mysql_fetch_array($query))
{
$id=$row['id'];
$job_detail1 = $row['job_description']; ?>
<td align="center"> <div class="popup" onclick="myFunction(<?php echo $id;?>)">
<a href="#myPopup<?php echo $id; ?>"> Click me!</a>
<span class="popuptext" id="myPopup"><?php echo "$job_detail1";?> </span>
</div></td>
</tr>
<?php
}
?>
第二个工作代码
<?php
//your prev code here
?>
<script>
function myFunction(id) {
var popup = document.getElementById("myPopup");
console.log(id)
popup.classList.toggle("show");
}
</script>
<table>
<?php
for($i=0;$i<10;$i++)
{
$id=$i;
$job_detail1 = 'desc'.$i; ?>
<td align="center"> <div class="popup" onclick="myFunction(<?php echo $id;?>)">
<a href="#myPopup<?php echo $id; ?>"> Click me!</a>
<span class="popuptext" id="myPopup"><?php echo "$job_detail1";?> </span>
</div></td>
</tr>
<?php
}
?>
</table>