简单问题 Vanilla JS 显示不匹配的按钮
Simple Question Vanilla JS Show Unmatch Buttons
我有 3 个按钮。当我单击元素数组中的一个按钮时,其他按钮将被禁用。我如何记录不匹配的按钮。请帮忙!谢谢
btnItem.addEventListener("click", () => {
btnList.forEach((activeCurrent) => {
if (btnItem.id === activeCurrent.id) {
//Have Three Button Select active clicked console.log(show others)
}
});
});
});
(function() {
const buttonList = document.querySelectorAll('button')
const onClickButton = (e) => {
buttonList.forEach(button => {
if (button !== e.currentTarget) {
console.log(button)
}
})
}
buttonList.forEach(button => button.addEventListener('click', onClickButton))
}
)();
<button>btn1</button>
<button>btn2</button>
<button>btn3</button>
我有 3 个按钮。当我单击元素数组中的一个按钮时,其他按钮将被禁用。我如何记录不匹配的按钮。请帮忙!谢谢
btnItem.addEventListener("click", () => {
btnList.forEach((activeCurrent) => {
if (btnItem.id === activeCurrent.id) {
//Have Three Button Select active clicked console.log(show others)
}
});
});
});
(function() {
const buttonList = document.querySelectorAll('button')
const onClickButton = (e) => {
buttonList.forEach(button => {
if (button !== e.currentTarget) {
console.log(button)
}
})
}
buttonList.forEach(button => button.addEventListener('click', onClickButton))
}
)();
<button>btn1</button>
<button>btn2</button>
<button>btn3</button>