jQuery弹出消息框在while循环中工作 [英] jquery popup message box working in the while loop

查看:75
本文介绍了jQuery弹出消息框在while循环中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在while循环中有一个弹出消息框,但是在弹出地址字段中,所有条目都显示相同的地址.

I have a popup message box working in the while loop, but in the popup address field the same address is shown for all entries.

有人可以告诉我我在做什么错吗?

Can anyone tell me what I'm doing wrong?

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>

<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>

弹出窗口在表格的每一行中显示相同的地址

推荐答案

问题是您在每个div的弹出窗口中使用了相同的ID.因此,无论您调用什么代码打开弹出窗口,它都将始终打开第一个弹出窗口.您需要这样的东西:

The problem is you're using the same ID in the popup for each div. Therefore no matter what code you call to open the popup, it will always open the first popup. You need something like this:

<script type="text/javascript">
$(document).ready(function() {
    $('.button').click(function(e) { 
        id = $(this).attr('id').substr(3);
        //alert(id); //uncomment this line to check ID's are coming through fine.
        $('#modal' + id).reveal({ 
            animation: 'fade',                   
            animationspeed: 600,                       
            closeonbackgroundclick: true,              
            dismissmodalclass: 'close'   
        });
    return false;
    });
});
</script>

<table>
<?php
$i = 0;
$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="#" id="btn<?php echo $i; ?>" 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 class="modal" id="modal<?php echo $i++; ?>">
<div class="heading">
Sign Up! Customer's Address
</div>
<div class="content">
<p><?php echo $row1['address']; ?></p>
</div>
</div>

<Popup End>

<?php }?>
</table>

请注意将其他div从ID更改为Class.您只能在一个页面上使用一次ID.如果您多次重复使用某些东西,那么它应该是一个类.

Note the change of the other div's from ID to Class. You should only use an ID once on a page. If you reuse something more than once it should be a Class.

您还错误地标记了标签.这是Javascript/HTML问题,而不是PHP问题.

Also you mislabelled your tags. This is a Javascript / HTML issue, not a PHP one.

这篇关于jQuery弹出消息框在while循环中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆