This is the error I get using .classList.contains()
(这是我使用.classList.contains()
遇到的错误)
Uncaught TypeError: Cannot read property 'contains' of undefined
(未捕获的TypeError:无法读取未定义的属性“包含”)
and please explain why it does not work: I need it for my apprenticeship
(并请解释为什么它不起作用:我的学徒需要它)
<div class="game-grid">
<button class="covered" <?php print $array[0]?>></button>
<button class="covered" <?php print $array[1]?>></button>
<button class="covered" <?php print $array[2]?>></button>
<button class="covered" <?php print $array[3]?>></button>
<button class="covered" <?php print $array[4]?>></button>
<button class="covered" <?php print $array[5]?>></button>
<button class="covered" <?php print $array[6]?>></button>
<button class="covered" <?php print $array[7]?>></button>
<button class="covered" <?php print $array[8]?>></button>
<button class="covered" <?php print $array[9]?>></button>
</div>
<script>
let buttons = document.getElementsByClassName("covered");
if(buttons.classList.contains("choosen") == false){
for (button of buttons) {
button.addEventListener("click", function(event){
event.target.classList.add("choosen");
event.target.classList.remove("covered");
});
}
}
</script>
ask by lp chickenwigs translate from so