gpt4 book ai didi

javascript - 在 Javascript 中使用 insidetext 来捕获值

转载 作者:行者123 更新时间:2023-11-28 05:37:24 26 4
gpt4 key购买 nike

我正在尝试使用 Javascript 捕获页面以下 HTML 中的值“Lusaka”

<div class="flight-list-container" id="outbounds">

<div data-wl-section="itineraryHeader" class="flight-list-section flight-list-header-container" id="outbounds-header-container">
<div class="flight-info">
<h2 class="translate wasTranslated" data-wl-translate="label.flc.itineraryHeader.departing">Outbound flight</h2>
<div class="xchnge-section-dl">
<span class="translate xchnge-section-dt wasTranslated" data-wl-translate="label.flc.itineraryHeader.flyingFrom">From</span>
<span class="xchnge-section-dd"><span class="translate wasTranslated" data-wl-translate="City.LHR">London</span>, <span class="translate wasTranslated" data-wl-translate="Country.GB">United Kingdom</span> (LHR)</span>
<span class="translate xchnge-section-dt wasTranslated" data-wl-translate="label.flc.itineraryHeader.flyingTo">To</span>
<span class="xchnge-section-dd"><span class="translate wasTranslated" data-wl-translate="City.LUN">Lusaka</span>, <span class="translate wasTranslated" data-wl-translate="Country.ZM">Zambia</span> (LUN)</span>
</div>
<p class="translate wasTranslated" data-wl-translate="label.flc.itineraryHeader.disclaimer">Lorem ipsum</p> </div>
</div>

使用以下代码,但不知道如何区分持有 FlyingFrom 和 FlyingTo 值的类

function() {

var destination = document.getElementById("outbounds-header-container").getElementsByClassName("translate wasTranslated")[1].innerText

return destination

}

最佳答案

您可以使用 jQuery 并通过以下代码获取值

$('.xchnge-section-dl > span.translate').each(function(){
alert( $(this).text()); //text in the container
})

希望这有帮助!!

关于javascript - 在 Javascript 中使用 insidetext 来捕获值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39241637/

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