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

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

javascript - 在节点集合上使用classList(Using classList on a node collection)

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

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

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...