【发布时间】:2019-06-17 16:50:22
【问题描述】:
我希望有人输入代码,并让脚本将<p id="output"> 更改为与代码对应的字母
function decode() {
var y = document.getElementById("code").value;
if (y == "GE56D7B") {
document.getElementById("output").innerHTML = "a";
}
if (y == "L9OSD4W") {
document.getElementById("output").innerHTML = "b";
}
if (y == "HDD218F") {
document.getElementById("output").innerHTML = "c";
}
if (y == "LO9P14A") {
document.getElementById("output").innerHTML = "d";
}
if (y == "YY6CZX3") {
document.getElementById("output").innerHTML = "e";
}
}
<input type="text" id="code" placeholder="Enter code here">
<button onclick="decode()">Enter</button>
<p id="output"></p>
【问题讨论】:
-
看起来它工作得很好。有什么问题?
-
@David 当我运行它时,“输出”中什么也没有出现,背景是黑色,但所有其他文本都是白色的,因为我制作了 body{ color: #fffff; } 在
-
嗯,您在此页面上向我们展示的代码实际上是按照此页面上的设计工作的。单击问题中的“运行代码 sn-p”以查看它。没有任何明显的问题,我们无能为力。
-
如果问题在于样式,请将 CSS 添加到您的 sn-p。
-
您是否在输入中输入了带有大写字母的代码?
标签: javascript html object