PHP代码:
<?php
$i = 0;
foreach ($this->productlist as $pro) {
?>
<div class="link"><a href="index.php?option=com_ecommerce&view=detail&id=$pro->id" class="basic"></a></div>
<?php
$i++;
}
?>
JS代码
<script>
jQuery(function(){
var link = $('.link .basic').attr('href');
alert(link);
});
</script>
当前输出:
index.php?option=com_ecommerce&view=detail&id=1
我想要的输出:
index.php?option=com_ecommerce&view=detail&id=1
index.php?option=com_ecommerce&view=detail&id=2
index.php?option=com_ecommerce&view=detail&id=3
index.php?option=com_ecommerce&view=detail&id=n
我做错了什么?
答案 0 :(得分:2)
$('.link .basic').each(function () {
alert($(this).attr('href'));
});