Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
416 views
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...