Zobacz mój kod poniżej. Chcę pobrać wartość href z HTML. Utworzę logikę dla tego, jak najpierw policz wszystkie Div, a następnie pobieraj wszystkie wartości OBE, ale problem jest problemem, że nie ma żadnej wyjątkowej klasy ani identyfikatora i chcę pobrać jeden po drugim.
<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>
Chcę dostać atrybut atrybutu HREF w ID. Czy to możliwe, stworzymy, że javascript nie zmienia się tylko javascript w klasie div lub klasie, ponieważ wszystkie są w kodzie joncube.
0
Pritesh Mahajan
13 sierpień 2014, 12:20
2 odpowiedzi
Najlepsza odpowiedź
Użyj map()
w jQuery, aby uzyskać dowolną wartość HREF w tablicy
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);
PRÓBNY
1
Balachandran
13 sierpień 2014, 08:31
Może to przejść do komentarza, ale nie można go poprawnie formatować w komentarzu. Jeśli tylko coś, co chcesz uzyskać wszystkie HREF, które są wewnątrz Div, która ma klasa JR-Layout-zewnętrzna, to powinno to zrobić.
$(document).ready(function () {
$('.jr-layout-outer').find('a').each(function () {
console.log($(this).attr('href'));
})
});
0
SSA
13 sierpień 2014, 08:32