一种在跨度内查找文本的方法

时间:2017-07-16 09:08:11

标签: javascript html css

有没有办法在div内部获取文本,该文本位于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>

1 个答案:

答案 0 :(得分:0)

在以下行的帮助下,您将获得text的{​​{1}}

sf-button-ext__content

尝试以下javascript,

document.getElementsByClassName('sf-button-ext__content')[0].textContent;
window.onload = function() {
  var element = document.getElementsByClassName('sf-button-ext__content');
  console.log(element[0].textContent);
}