请参阅下面的代码。我想从html中获取href值。我已经创建了一个逻辑,就像首先计算所有div,然后通过obe获取所有值,但问题是没有任何唯一的类或Id,我想逐个获取。
<script>
jQuery(document).ready(function(){
var mylength = jQuery(".jr-layout-outer").length;
console.log(mylength);
for (i= 1; i <= mylength ; i++) {
var aa = jQuery(".jr-layout-outer .jrListingContent .jrListingThumbnail a").attr("href");
console.log(aa);
};
});
</script>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
<div class="jr-layout-outer">
<div class="jrListingContent">
<div class="jrListingThumbnail">
<a href="index.php?option=com_content&view=article&id=3">
<img class="jrMediaPhoto" title="" alt="" src="reviews/photos/thumbnail/120x120c/a3/5e/bc/m-mustermann-54-1401265222.png">
</a>
</div>
</div>
</div>
我想在Id中获取锚标记href属性。 这是否可能我们将创建一个make只有javascript不会在div或类中更改因为所有都在Ioncube代码中。
答案 0 :(得分:1)
在jquery中使用map()
来获取数组中的所有href值
var aa = jQuery(".jr-layout-outer .jrListingThumbnail a").map(function () {
//console.log($(this).attr("href")); see in console
return $(this).attr("href");
}).get();
alert(aa);
答案 1 :(得分:0)
这可能会发表评论,但无法在评论中正确格式化。如果你想得到所有href里面的东西,它们都有类jr-layout-outer,那么就应该这样做。
$(document).ready(function () {
$('.jr-layout-outer').find('a').each(function () {
console.log($(this).attr('href'));
})
});