css 未捕获的引用错误:未定义选择器

gt0wga4j  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(117)

我正在做一个Youtube Tutorial关于制作一个基本的聊天机器人,我使用JS,Python 3.11.4,HTML,Flask和CSS。大部分代码是正确的,但每次我运行它,我得到一个错误,无法打开聊天气泡的东西。
这里是错误:

Uncaught ReferenceError: selectors is not defined

字符串
下面是JS代码的相关部分:

class Chatbox {
  constructor() {
    this.args = {
      openButton: document.querySelector(selectors, ".chatbox__button"),
      chatBox: document.querySelector(selectors, ".chatbox__support"),
      sendButton: document.querySelector(selectors, ".send__button"),
    };
    this.state = false;
    this.messages = [];
  }

// Rest of functions and so on


下面是HTML,因为它可能会出错:

<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

<head>
    <meta charset="UTF-8">
    <title>Chatbot</title>
</head>
<body>
<div class="container">
    <div class="chatbox">
        <div class="chatbox__support">
            <div class="chatbox__header">
                <div class="chatbox__image--header">
                    <img src="https://img.icons8.com/color/48/000000/circled-user-female-skin-type-5--v1.png" alt="image">
                </div>
                <div class="chatbox__content--header">
                    <h4 class="chatbox__heading--header">Chat support</h4>
                    <p class="chatbox__description--header">Hi. My name is Sam. How can I help you?</p>
                </div>
            </div>
            <div class="chatbox__messages">
                <div></div>
            </div>
            <div class="chatbox__footer">
                <input type="text" placeholder="Write a message...">
                <button class="chatbox__send--footer send__button">Send</button>
            </div>
        </div>
        <div class="chatbox__button">
            <button><img src="{{ url_for('static', filename='images/chatbox-icon.svg') }}" /></button>
        </div>
    </div>
</div>

    <script>
        $SCRIPT_ROOT = {{ request.script_root|tojson }};
    </script>
    <script type="text/javascript" src="{{ url_for('static', filename='app.js') }}"></script>

</body>
</html>

5vf7fwbs

5vf7fwbs1#

只要使用document.querySelector(".chatbox__button")第一个参数需要选择器,你只是传递了一个未定义的变量,这就是为什么它不工作

相关问题