0

对于我的 php 动态驱动的网站mobileapps.co,它正在从数据库中提取产品。我还在运行 jquery 来为每个产品创建气泡弹出窗口。

如何为所有产品循环我的 javascript,我正在使用以下代码

<ul>
    <script>
   $(document).ready(function() {
    $('.popup0').CreateBubblePopup({
        position: 'top',
        align: 'center',
        innerHtml: '<?php echo $result['
        embeddedcode ']; ?><p style="float:left"><?php echo substr($result['
        appdesc '], 0, 100); ?><img src="images/rate-off.gif" /><img src="images/rate-off.gif" /><img src="images/rate-on.gif" /><img src="images/rate-on.gif" /><img src="images/rate-on.gif" /></p>',
        innerHtmlStyle: {
            color: '#FFFFFF',
            'text-align': 'center'
        },
        themeName: 'all-black',
        themePath: 'images/jquerybubblepopup-theme'
    });
});​
</script>
<?php foreach ($fetchapps->arr as $result): ?>
  <li id="app-<?php echo $result['appid']; ?>" class="popup0">
<div class="icon">
  <a href="app-details.php?result=<?php echo $result['appid']; ?>"><?php echo      $result['embeddedcode']; ?></a>
</div>
<p>
      <a href="app-details.php?result=<?php echo $result['appid']; ?>"><?php echo substr($result['apptitle'], 0, 15); ?></a>
  <span><a href="app-details.php?result=<?php echo $result['appid']; ?>"><?php echo $result['category']; ?></a></span>
  <strong><?php if($result['appprice'] != 'free') echo $result['appprice']; ?></strong>
  <b><?php if($result['appprice']!='free'){ ?>$.<?php } ?><?=$result['appprice']?></b>
</p>
  </li>  
<?php endforeach; ?>
</ul>
4

2 回答 2

0

也许这个?

<?php $rid = rand(0, pow(10, 7)); ?>

$(document).ready(function() {
    $('.<?php echo $rid; ?>').CreateBubblePopup({
        ....
    });
});

markup ...

<li id="app-<?php echo $result['appid']; ?>" class="popup0 <?php echo $rid; ?>">
于 2012-03-24T02:00:02.863 回答
0

尝试这个..

            $(document).ready(function() {
                // notice what i've added.. 
                // i added a forloop and tried to get the number of popup0 class
                for (var i = 0; i < $('.popup0').length(); i++) {
                    $('.popup0').eq(i).CreateBubblePopup({
                        position: 'top',
                        align: 'center',
                        innerHtml: '<?php echo $result['
                        embeddedcode ']; ?><p style="float:left"><?php echo substr($result['
                        appdesc '], 0, 100); ?><img src="images/rate-off.gif" /><img src="images/rate-off.gif" /><img src="images/rate-on.gif" /><img src="images/rate-on.gif" /><img src="images/rate-on.gif" /></p>',
                        innerHtmlStyle: {
                            color: '#FFFFFF',
                            'text-align': 'center'
                        },
                        themeName: 'all-black',
                        themePath: 'images/jquerybubblepopup-theme'
                    });
                }
            });

希望这可以帮助

于 2012-03-24T01:20:24.973 回答