对于我的网站mobileapps.co,它是动态驱动的PHP,它从数据库中提取产品。我也在运行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>
答案 0 :(得分: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'
});
}
});
希望这会有所帮助
答案 1 :(得分: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; ?>">