I'm trying to create a small RPG game. 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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.