gpt4 book ai didi

javascript - 一种在范围内查找文本的方法

转载 作者:行者123 更新时间:2023-11-28 04:25:10 25 4
gpt4 key购买 nike

有没有办法获取位于 div 内的跨度内的文本,其中唯一的标识符是类名?谢谢

    <div class="popup-footer-btns-wrapper"> <!-- ngIf: popup.buttons.OK -->
<button sf-button="" sf-name="popup-ok" ng-if="popup.buttons.OK" ng-
disabled="okLocked || popup.buttons.OK.disabled()" ng-click="ok()" ng-
class="popup.buttons.OK.colour ? popup.buttons.OK.colour : 'grey'"
class="popup-footer-button ng-scope ng-isolate-scope sf-button sf-
button-ext grey" style="">
<span class="sf-button-ext__content"><ng-
transclude>Apply</ng-transclude></span>
</button><!-- end ngIf:
popup.buttons.OK --> <button sf-name="popup-cancel" class="popup-footer-
button sf-link underline ng-binding" ng-click="cancel()">Cancel</button>
</div>

最佳答案

借助以下行,您将获得span sf-button-ext__contenttext

document.getElementsByClassName('sf-button-ext__content')[0].textContent;

尝试下面的 JavaScript,

window.onload = function() {
var element = document.getElementsByClassName('sf-button-ext__content');
console.log(element[0].textContent);
}
<div class="popup-footer-btns-wrapper">
<!-- ngIf: popup.buttons.OK -->
<button sf-button="" sf-name="popup-ok" ng-if="popup.buttons.OK" ng- disabled="okLocked || popup.buttons.OK.disabled()" ng-click="ok()" ng- class="popup.buttons.OK.colour ? popup.buttons.OK.colour : 'grey'" class="popup-footer-button ng-scope ng-isolate-scope sf-button sf-
button-ext grey" style="">
<span class="sf-button-ext__content"><ng-
transclude>Apply</ng-transclude></span>
</button>
<!-- end ngIf:
popup.buttons.OK --><button sf-name="popup-cancel" class="popup-footer-
button sf-link underline ng-binding" ng-click="cancel()">Cancel</button>
</div>

关于javascript - 一种在范围内查找文本的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45126878/

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