1

php jquery弹出消息框在while循环中工作,但在弹出地址字段中显示所有条目的相同地址,任何人都可以告诉我我在哪里做错了提前谢谢

Html Jquery 脚本

<script type="text/javascript">
    $(document).ready(function() {
        $('#button').click(function(e) { 
            $('#modal').reveal({ 
                animation: 'fade',                   
                animationspeed: 600,                       
                closeonbackgroundclick: true,              
                dismissmodalclass: 'close'   
            });
        return false;
        });
    });
</script>

Html 表格和 PHP 页面

<table>
$query1=mysql_query("select * from customers order by id desc");
while($row1=mysql_fetch_array($result))
{
?>
<tr>
<td><div align="center"><?php echo $row1['firstname']; ?></div></td>
<td><div align="center"><?php echo $row1['lastname']; ?></div></td>
<td><div align="center"><?php echo $row1['dob']; ?></div></td>
<td><div align="center"><?php echo $row1['email']; ?></div></td>
<td><div align="center"><a href="#" class="button">Address</a></div></td>
<td><div align="center"><?php echo $row1['phone']; ?></div></td>
<td><div align="center"><?php echo $row1['country']; ?></div></td>
<td><div align="center"><?php echo $row1['city']; ?></div></td>
</tr>


<Popup Start> 

<div id="modal">
<div id="heading">
Sign Up! Customer's Address
</div>
<div id="content">
<p><?php echo $row1['address']; ?></p>
</div>
</div>

<Popup End>

<?php }?>
</table>
4

2 回答 2

1

在 HTML 中

将此行更改为:

<td><div align="center"><a href="#" id="button">Address</a></div></td>

这个:

<td><div align="center"><a href="#" class="button">Address</a></div></td>

&

将此行更改为:

<div id="modal">

这个:

<div class="modal">

Javascript:

$('.button').click(function(e) { 

            $(this).closest('tr').find('.modal:first').reveal({ 
                animation: 'fade',                   
                animationspeed: 600,                       
                closeonbackgroundclick: true,              
                dismissmodalclass: 'close'   
            });
        return false;
        });
于 2013-02-16T12:26:34.683 回答
0

尝试为这样的所有按钮提供唯一的 id

<td><div align="center"><a href="#" id="button_<?php echo $row1['id'];?>">
    Address</a>
</div></td>

然后根据该按钮的 id 值应用弹出按钮单击,并像这样编辑您的 jquery

<script type="text/javascript">
$(document).ready(function() {
    $("input[id^='button']").click(function(e) { 
        $('#modal').reveal({ 
            animation: 'fade',                   
            animationspeed: 600,                       
            closeonbackgroundclick: true,              
            dismissmodalclass: 'close'   
        });
    return false;
    });
});
</script>
于 2013-02-16T12:19:43.610 回答