【发布时间】:2015-12-12 15:41:33
【问题描述】:
以下代码仅适用于表格第一行中的按钮。其他自动生成的行的按钮不会打开任何对话框。我想问题是我没有为每个按钮分配不同的id。我怎样才能做到这一点?我读了this page,但没有任何效果。
<table class="table-hovered">
<tr>
<th class="text-left big">TITOLO</th>
<th class="text-centered" align="center">
<img src="img/w.png" width="35" height="35" title="wikipedia" align="middle"><br>
wikipedia
</th>
</tr>
<? while($objResult = mysql_fetch_array($objQuery))
{ ?>
<tr>
<td class="text-left"><?=$objResult["titolo"];?></td>
<td class="text-centered">
<button id="trigger" class="btn">definizione</button>
<div id="dialog" style="display: none;" title="definizione">
<iframe frameborder="0" scrolling="yes" width="480" height="380" src="def.php?titolo=<?=$objResult['titolo'];?>"></iframe>
</div>
</td>
<script>
$("#trigger").click(function() {
$("#dialog").dialog("open");
});
$("#dialog").dialog({
autoOpen: false,
position: 'center' ,
title: 'definizione',
draggable: true,
width: 500,
height: 400,
resizable: true,
modal: true,
show: 'slide',
hide: 'fade'
});
</script>
</tr>
<? } ?>
</table>
【问题讨论】:
-
因为你在做一个循环,你有
n数量的<button id="trigger">和n数量的<div id="dialog">。由于ids 应该是唯一的,所以 jQuery(/javascript) 只会找到并绑定到第一个。您需要使这些ids 独一无二,或者将它们更改为<button class="trigger">/<div class="dialog">和$(".trigger").click(function() {$(".dialog").dialog("open"); });/$(".dialog").dialog({...的类 -
这个解决方案有效,但是当我点击任何按钮时,所有对话框窗口都会打开(一个在另一个上)。
标签: php jquery while-loop dialog