0

我试图在弹出窗口中显示产品描述。意思是当我点击产品链接时,会打开一个弹出窗口并显示产品描述。但这里出了点问题。每个产品链接都显示第一个产品描述。我的代码在下面。请帮帮我。

Javascript:

    <script language="JavaScript">
    function displayPopup(alert_MSG) 
    {
       var theDetail = document.getElementById('flyBox');
            theDetail.style.display="block";
    }

    function closePopup(alert_MSG)
    {

        var theDetail = document.getElementById('flyBox');

        if (theDetail.style.display=="block") 
        {
            theDetail.style.display="none";
        }
    }
    </script>

HTML:

                        <a href="javascript:displayPopup('flyBox')" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
                      <div id="flyBox" style="display:none;">
                      <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>

                    <td align="center">
                    <table border="0" cellspacing="0" cellpadding="0">
                    <tr>
                    <td class="borderWindow">
                    <div class="container">
                    <div id="closeButton"><a href="javascript:closePopup('flyBox')"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></a></div>
                    <div class="content">
                    <table width="600" border="0" cellspacing="20" cellpadding="0">
                    <tr>
                    <td>
                    <div id="myMessageBox" name="myMessageBox">
                    <table width="100%"  border="0" cellspacing="2" cellpadding="0">
                    <tr>
                    <td class="colheadingL"><font color="white">Description</font></td>
                    </tr>
                    <tr>

                            <td ><?php echo $img; ?></td>
                            <td>Book Name:</td>
                            <td ><?php echo $row['pname']; ?></td>
                            <td class="text1">MRP:</td>
                            <td><?php echo $row['price'];?> </td>


                    </tr>



                </table>
                </div>
                </td>
                </tr>
                </table>
                </div>
                </div>
                </td>
                </tr>
                </table>
                </td>
                </tr>
                </table>
                </div> 

但弹出是打开点击超链接。但问题是在所有产品中只显示第一条记录

4

2 回答 2

1

您的模板脚本中没有任何循环,这就是为什么您只看到一个记录可视化的原因。

我不确切知道您的代码在您发布的代码段之外是如何组织的,但假设您的数据行位于$rows数组变量中,代码将如下所示:

<? foreach($rows as $row) { ?>
<tr>
  <td ><?php echo $img; ?></td>
  <td>Book Name:</td>
  <td ><?php echo $row['pname']; ?></td>
  <td class="text1">MRP:</td>
  <td><?php echo $row['price'];?> </td>
</tr>
<? } ?>
于 2013-07-29T12:12:36.327 回答
0

尝试将每个 DIV 的 ID 设为唯一。

以下是示例代码,请尝试根据您的要求使用它

<script language="JavaScript">
function displayPopup(id) 
{
   var theDetail = document.getElementById(id);
        theDetail.style.display="block";
}

function closePopup(id)
{

    var theDetail = document.getElementById(id);

    if (theDetail.style.display=="block") 
    {
        theDetail.style.display="none";
    }
}
</script>


<?php for($i=0;$i<4;$i++){?>
<div>
             <a href="javascript:displayPopup('flyBox_<?php echo $i;?>')" title="View larger image" class="ui-icon ui-icon-zoomin">View larger</a>
             <div id="flyBox_<?php echo $i;?>" style="display:none;">
                 <div id="closeButton"><a href="javascript:closePopup('flyBox_<?php echo $i;?>')"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></a></div>
                  <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center">
                        <?php echo "Div ".$i. " Content comes here";?>
                    </td>
                </tr>
                </table>
            </div> 
</div>
<?php }?>
于 2013-07-29T12:45:13.753 回答