Uncaught ReferenceError: selectors is not defined

huangapple go评论79阅读模式
英文:

Uncaught ReferenceError: selectors is not defined

问题

我正在制作一个关于创建基本聊天机器人的YouTube教程,我正在使用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 = [];
  }

// 其余函数等等

这是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>
英文:

I am doing a Youtube Tutorial on making a basic chatbot I am using JS, Python 3.11.4, HTML, Flask, and CSS. Most of the code is correct but every time I run it I get a error and cannot open the chat bubble thing.

Heres the error:

Uncaught ReferenceError: selectors is not defined

here is the relevant part of the JS code:

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

// Rest of functions and so on

Here is the HTML because it might be giving errors:

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;style.css&#39;) }}&quot;&gt;

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

    &lt;script&gt;
        $SCRIPT_ROOT = {{ request.script_root|tojson }};
    &lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;{{ url_for(&#39;static&#39;, filename=&#39;app.js&#39;) }}&quot;&gt;&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;

答案1

得分: 1

"Just use document.querySelector(".chatbox__button") the first argument requires the selector, you are just passing a variable which is undefined that's why it didn't work."

英文:

Just use document.querySelector(&quot;.chatbox__button&quot;)
the first argument requires the selector, you are just passing a variable which is undefined that's why it didn't worked

huangapple
  • 本文由 发表于 2023年7月18日 14:39:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710108.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定