我正在创建一个带有一个输入和一个按钮的“算命先生”功能。用户写下一个问题,然后可以单击该功能的按钮来完成。然而,当用户点击回车时什么也没有发生。我尝试了在这里找到的一些解决方案,但没有任何效果。我没有做很多 JavaScript。谢谢!
var outcomes = [
"It is certain",
"It is decidedly so",
"Without a doubt",
"Yes - definitely",
"You may rely on it",
"As I see it, yes",
"Most likely",
"Outlook good",
"Ask again later",
"Better not tell you now",
"Cannot predict now",
"Concentrate and ask again",
"Don’t count on it",
"No",
"My reply is no",
"My sources say yes",
"Outlook is not so good",
"Yes",
"Yes, it would benefit you",
"Reply hazy, try again",
"Very doubtful",
"Signs point to yes",
"No, it wouldn't benefit you"
];
function ask() {
var x = document.getElementById("input-box").value;
var sel = Math.floor(Math.random() * outcomes.length);
var b8 = outcomes[sel];
if (x.indexOf('?') + 1) {
document.getElementById("answer").innerHTML = b8;
} else {
document.getElementById("answer").innerHTML = "Try with a question mark (?)";
}
}
<div class="ask">
<input id="input-box">
<div class="button" onclick="ask()">
<img src="img/ask-1.png" onmouseover="this.src='img/ask-2.png';" onmouseout="this.src='img/ask-1.png';">
</div>
<p id="answer"></p>
</div>
慕婉清6462132
HUH函数
相关分类