2011-11-29 86 views
1

我想在我的网站上显示工具提示,和我使用这个代码:http://flowplayer.org/tools/demos/tooltip/table.htmljQuery的工具提示在PHP“而”循环不工作

我使用while循环创建表行<tr>。这里是我的工具提示<div>的样子:

<td class="maandgem">&euro; <?= round($monthavg, 2); ?></td> 
<div id="tooltip" class="tooltip"> 
    Shipping: <?= $row['price_shipping']; ?><br /> 
    Price: <?= $row['price']; ?><br /><br /> 
    Total: <?php echo $row['price'] + $row['price_shipping'] + ($row['abo_price'] * $row['abo_time']); ?> 
</div>  

而且这个工程按计划,它计算总价格为每台<tr>。我遇到的问题是,当我将鼠标悬停在<td class=maandgem>上时,它始终显示相同的第一个工具提示。

因此,每个<TD>只显示1个工具提示,第一个创建。而不是每行独特的工具提示。 PHP部分的作品 - 有独特的<TD>被创建。我使用这个代码(它的默认,我不明白jQuery的多)

$(document).ready(function() { 
    $(".maandgem").tooltip({ 
     tip: '#tooltip', 
     position: 'bottom left', 
     delay: 0 
    }); 
}); 

我还包括本.js和我有工具提示基本样式表。

<script src="http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js"></script> 

回答

1

我想这是因为您使用的id为工具提示,并且id必须是唯一的,因此jQuery只会选择第一个。

尝试使用class-attribute代替,并选择它。

+0

感谢您的回复。我将如何做到这一点? “maandgem”。

0

是的,如果类将被用来代替ID,那么它也会在循环中工作。 我测试过了,工作正常。

<link rel="stylesheet" href="jquery-ui-1.10.4.custom.css"> 
    <script src="jquery-1.10.2.min.js"></script> 
    <script src="jquery-ui-1.10.4.custom.js"></script> 

    <script> 
     $(function() { 
      $(".show-option").tooltip({  
       show: 
       {  
        effect: "slideDown",  
        delay: 250  
       }, 

       position: 
       {  
        my: "center top",   
        at: "center"  
       } 
      }); 
     }); 
    </script> 
</head> 
<body> 
    <h2 class="show-option" title="Testing Tooltip">ToolTip</h2> 
</body>