简体   繁体   English

错误...对话未定义

[英]Error... Talk is not defined

I'm trying to create a small RPG game.我正在尝试创建一个小型 RPG 游戏。 But I keep receiving this error.但我一直收到这个错误。 I have my function (talk) defined.我定义了我的功能(谈话)。 (activated by the talk button) Yet it says it's not defined. (由通话按钮激活)但它说它没有定义。

<!DOCTYPE HTML>
    <head>

    </head>
    <title> </title>
    <body>
<script>

        function talk() {
                document.querySelector(".options").innerHTML = "<button onclick="fine()">I'm fine.</button>";
                }
    </script>
    <div class="options">
    <button onclick="talk()">Try it</button>
    <button onclick="silent()">Stay Silent</button>
    </div>
        </body>

There's an error in the use of single and double quotation.单引号和双引号的使用有错误。 Here's the fix:这是修复:

function talk() {
    document.querySelector(".options").innerHTML = "<button onclick='fine()'>I'm fine.</button>";
}

After doing this you'll get "fine is not defined".执行此操作后,您会得到“罚款未定义”。 So you'll need to do something like this:所以你需要做这样的事情:

function fine(){
    alert('I am fine');
}

Anyway, I don't get why are you trying to do this, but hope it helps!无论如何,我不明白你为什么要这样做,但希望它有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM