1

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>

<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

1 に答える 1

0

問題は、各divのポップアップで同じIDを使用していることです。したがって、ポップアップを開くためにどのコードを呼び出しても、常に最初のポップアップが開きます。次のようなものが必要です。

<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はページで1回だけ使用する必要があります。何かを複数回再利用する場合は、クラスにする必要があります。

また、タグに誤ったラベルを付けました。これはJavascript/HTMLの問題であり、PHPの問題ではありません。

于 2013-02-16T23:15:03.297 に答える