gpt4 book ai didi

javascript - 使用 javascript 访问数组 item prop 值

转载 作者:行者123 更新时间:2023-12-02 15:32:11 24 4
gpt4 key购买 nike

我有一个 div block 数组,我正在尝试访问每个 div block 的“时间”标签的innerHTML。我怎样才能访问这个值?

<div class="review-full-review-single-review-wrap">
<span class="review-full-timestamp">
<time itemprop="datePublished" datetime="2015-07-29T11:25:47-07:00">July 29, 2015</time>
</span>
<p class="review-camo-rewards">Reward points earned</p>
</div>

<div class="review-full-review-single-review-wrap">
<span class="review-full-timestamp">
<time itemprop="datePublished" datetime="2015-07-29T11:25:47-07:00">July 1, 2015</time>
</span>
<p class="review-camo-rewards">Reward points earned</p>
</div>

最佳答案

你可以这样做:

var elems = document.getElementsByClassName("review-full-review-single-review-wrap")
for (var i = 0; i < elems.length; i++) {
var timeElems = elems[i].getElementsByTagName("time");
for (var j = 0; j < timeElems.length; j++) {
console.log(timeElems[j].innerHTML)
}
}

演示:http://jsfiddle.net/q311LcL3/

关于javascript - 使用 javascript 访问数组 item prop 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33222887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com