gpt4 book ai didi

javascript - 使用javascript创建基本按钮

转载 作者:行者123 更新时间:2023-11-30 09:17:16 25 4
gpt4 key购买 nike

我正在制作一个按钮,每次点击都会从“你”>“哇”>“旅行”变化。

但它会报错“Uncaught TypeError: onoff is not a function at HTMLInputElement.onclick (7.html:15)”

你能帮我解决这个问题吗?

function onoff() {
currentvalue = document.getElementById('onoff').value;

if (currentvalue == "you") {
document.getElementById('onoff').value = "wow";
} else if (currentvalue == "wow";) {
document.getElementById('onoff').value = "travel";
} else {
document.getElementById('onoff').value = "you";
}
}
<input type="button" value="you" id="onoff" onclick="onoff();">

最佳答案

function onoff() {
var currentvalue = document.getElementById('onoff').value;
if (currentvalue == "you") {
document.getElementById('onoff').value = "wow";
} else if (currentvalue == "wow") {
document.getElementById('onoff').value = "travel";
} else {
document.getElementById('onoff').value = "you";
}
}
<input type="button" value="you" id="onoff" onclick="onoff()">

完成,一切正常:

我已经替换了 onclick="onoff();"else if (currentvalue == "wow";)

问题只是语法错误

关于javascript - 使用javascript创建基本按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54165392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com