如何从点击监听器访问按钮属性?我想访问 aria-expanded 来设置一些值;这是我得到的。
x.html
<button class="btn btn-secondary" (click)="customSearch($event.target)" type="button" data-toggle="collapse" data-target="#collapseForm" aria-expanded="false" aria-controls="collapseForm">Search</button>
x.ts
customSearch(e){
console.log("some event--->",e);
}
结果
最佳答案
由于您已经将 dom 对象作为参数传递,因此您可以使用 getAttribute 方法直接获取其属性
customSearch(buttonDOM) {
console.log("some event--->", buttonDOM.getAttribute('aria-expanded'));
}
关于javascript - 如何访问按钮的 aria 扩展值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60493253/