所以说我有这个HTML
<div class="board">
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
<button type="button" class="space"></button>
</div>
在javascript中我有这个
const changeSpot = () => {
this.textContent = "You clicked me!";
}
const spots = document.getElementsByClassName('space');
我如何做到这一点,以便changeSpot()可以引用正在使用它的按钮?我尝试在按钮上添加onclick =“ changeSpot”,但这似乎不起作用。如果重要的话,javascript函数位于名为gameBoard的模块中。感谢您的光临!