在Java脚本中使用IF OR Else

Using IF OR Else in Java Script

本文关键字:IF OR Else Java 脚本      更新时间:2023-09-26

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

http://pastebin.com/CuN5cq92

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

这是我陷入困境的部分:

var code = (e.keyCode ? e.keyCode : e.which);
var input = document.getElementById("text");
if (code == 13) {
    if (input == "Hungarian" || "Magyar") {
        window.open(Lang / hungarian / hungarian.html)
    }
}
<p>
  <mark class="smallwhite">Type in the desired language:</mark>
</p>
<input type="text" id="input" size="26">

您的代码中有两个错误:

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") {