在Java Script中使用IF OR Else

时间:2016-07-24 21:45:51

标签: javascript html

我目前正在为我的游戏社区制作一个网站,我做了它看起来像一个Linux终端(网站是http://fluffykillers.ml/,如果你有点好奇的话)我是初学者&#34程序员",我需要一些帮助,当我输入其中一个单词时,它不会做任何事情,这是我的整个index.html代码:

http://pastebin.com/CuN5cq92

我无法在此发布所有代码,抱歉!

这是我陷入困境的部分:

{{1}}

1 个答案:

答案 0 :(得分:0)

您的代码中有两个错误:

1)您需要获取输入中输入的实际值:

// This only retrieve the HTML element <input> 
var input = document.getElementById("text");
// To get the value you need to : 
var value = input.value;

// Will print the entered value in firebug /developer console of your browser
console.log(value); 

2)您的测试条件不正确:

// This will always evaluate to true (testing the string "Magyar" is always true)
// And you need to test for the value, not the "input" (HTML Element)
if (input == "Hungarian" || "Magyar") { 

应该是

if (value == "Hungarian" || value == "Magyar") {