如何使用JavaScript获取活动选项卡的文本值?
如何使用JavaScript获取活动选项卡的文本值?我无法修改页面上的代码,因为它是第三方web应用程序。在本例中,我希望返回值“basicinformation”。我假设有某种方法可以利用tabindex=0等,但我不知道如何利用如何使用JavaScript获取活动选项卡的文本值?,javascript,Javascript,如何使用JavaScript获取活动选项卡的文本值?我无法修改页面上的代码,因为它是第三方web应用程序。在本例中,我希望返回值“basicinformation”。我假设有某种方法可以利用tabindex=0等,但我不知道如何利用 谢谢 applyNow-active看起来是一个很好的类。这里的挑战是忽略子节点 let element = document.querySelector('.applyNow-active label'); let child = element.firstC
谢谢
applyNow-active
看起来是一个很好的类。这里的挑战是忽略子节点
let element = document.querySelector('.applyNow-active label');
let child = element.firstChild;
let texts = [];
while (child) {
if (child.nodeType == 3) {
texts.push(child.data);
}
child = child.nextSibling;
}
texts.join(""); // this is the text!
示例:以下是一种方法:
var textYouWant = document.querySelector('.applyNow-active>label').firstChild.textContent.trim();
获取.applyNow active
标签的第一个子项(textNode):
let activeElement=document.querySelector('.applyNow活动标签')
console.log(activeElement.firstChild.textContent.trim())
-
“基本信息”
应用步骤
-
“业务信息”
应用步骤
-
“个人信息”
应用步骤
是否有一种方法可以动态确定标签索引?仅供参考,标签索引与按tab键在网页中循环浏览时聚焦的顺序有关,与Sort的任何可视标签无关。请使用实际代码,而不是代码图像。