gpt4 book ai didi

javascript - 获取大型列表中元素的值

转载 作者:行者123 更新时间:2023-11-29 23:31:51 24 4
gpt4 key购买 nike

我研究了这个问题,看起来大多数答案都与检索节点列表中第一个元素的值有关,该元素具有唯一的 ID 或类名。

也就是说,我正在使用 Adob​​e DTM 来跟踪下面示例代码中的事件。想象一下以这种方式设置的充满 li 元素的页面。

<li id="af3a2eb0-cfe9-11e5-b131-6fc0b40730a0" class="theater__active__3-QdV theater__theater__nmQh3 theaterTheater">
<div class="theaterHead theater__header__2Skwj">
<div class="theater__logo__2uovm">
<img class="" src="image" alt="logo">
</div>
<div class="theaterInfo theater__theaterInfo__2dTbj">
<h3 class="theater__theaterName__1Pwxo">Arclight</h3>
<p class="theater__theaterAddress__16_be">10000 Wilshire Boulevard, Los Angeles, CA</p>
<span class="theater__distance__30qj2 theater__theaterAddress__16_be">4.4mi</span>
</div>
<div>
</div>
</div>
</li>

当单击其父 div 之一时,我试图获取“h3”元素的值。

到目前为止,我已将此设置为数据元素:

var myNodelist = document.querySelector(".theater__theaterName__1Pwxo");
var i;
for (i = 0; i < myNodelist.length; i++) {
return myNodelist[i].value;
}

但它实际上返回一个空值,我不确定为什么!

最佳答案

您可以在点击事件中使用以下表达式来获取元素文本(确保将其附加到事件规则中的 prop 或 evar 中:

%this.@text%

注意: this 将引用当前点击的元素。

希望这对您有所帮助。

关于javascript - 获取大型列表中元素的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47045348/

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