使用 ES6 切换 aria-expanded JavaScript
Toggle aria-expanded with ES6 JavaScript
我试图在单击按钮时在 true
和 false
之间切换 aria 标签。我已经尝试了几种似乎完全没有做的实现。下面是我目前正在使用的成功切换 class 的内容。我如何扩展它以在 true
和 false
之间切换 aria 扩展值?对我放轻松,我正在从 jQuery 过渡到 ES6。
const theTrigger = document.getElementById('mobile-form-control');
const theForm = document.querySelectorAll('.l-header__mobile-form');
theTrigger.onclick = function () {
for (const x of theForm) {
x.classList.toggle('show');
}
};
您可以通过将其值与 'true'
进行比较来切换属性。
x.ariaExpanded = x.ariaExpanded !== 'true';
我试图在单击按钮时在 true
和 false
之间切换 aria 标签。我已经尝试了几种似乎完全没有做的实现。下面是我目前正在使用的成功切换 class 的内容。我如何扩展它以在 true
和 false
之间切换 aria 扩展值?对我放轻松,我正在从 jQuery 过渡到 ES6。
const theTrigger = document.getElementById('mobile-form-control');
const theForm = document.querySelectorAll('.l-header__mobile-form');
theTrigger.onclick = function () {
for (const x of theForm) {
x.classList.toggle('show');
}
};
您可以通过将其值与 'true'
进行比较来切换属性。
x.ariaExpanded = x.ariaExpanded !== 'true';