【问题标题】:How to access the values of an Aria Combobox w/ Javascript or JQuery如何使用 Javascript 或 JQuery 访问 Aria 组合框的值
【发布时间】:2020-10-04 18:07:09
【问题描述】:

我有以下无法更改的 HTML(我无法影响的公司工具的一部分)。这是一个下拉菜单,我想在 Tampermonkey 脚本中使用 Javascript/JQuery 访问下拉菜单中的所有值(链接):

<div class="ant-select-selection ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-controls="e80ef4e8-f947-4351-88b3-136bb5f3d62f" aria-expanded="false" tabindex="0">

<div class="ant-select-selection__rendered"><div class="ant-select-selection-selected-value" title="6 - Live" style="display: block; opacity: 1;">6 - Live</div></div>

<div class="ant-select-selection-selected-value" title="6 - Live" style="display: block; opacity: 1;">6 - Live</div>
</div>

最终目标:添加一个按钮,只需单击即可从下拉列表中打开 5 个链接

我尝试了什么:

document.getElementsByClassName("ant-select-selection"):返回“未定义” document.querySelector("combobox"):返回“未定义”

我的理解

我知道当我点击下拉菜单时,

aria-expanded="false" 

更改为“true”和新类

ant-select-open, ant-select-focussed, ant-select-enabled

正在对元素。将 evenListener 添加到单击下拉列表并尝试在单击后访问值也不起作用(仅返回下拉列表的选定值,而不是全部)

但我不知道如何利用它来访问所有下拉值。

简而言之,我的问题:如何访问 aria 组合框下拉元素的值?

【问题讨论】:

    标签: javascript html jquery combobox wai-aria


    【解决方案1】:

    我复制了那个 html 并做了:

    var x = document.getElementsByClassName("ant-select-selection");
    x[0].innerHTML = "hello"
    

    它确实获得了对主要div 的引用。

    HTML 是动态的吗?可能您正试图在它被渲染之前访问它,或者该内容可能在 iframe 元素内。

    【讨论】:

    • 认为它是动态 HTML。我在这里期望的是在通过类名访问元素时返回的 HTML 集合,但如上所述,这不起作用。还有其他想法吗?
    • 将其包装在 setTimeout(function(){}, someTime) 中
    • 也试过setTimeout,结果还是“未定义”
    • iframe 里面什么都没有?
    猜你喜欢
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-15
    • 1970-01-01
    • 2015-08-21
    • 2011-12-31
    相关资源
    最近更新 更多