在Java脚本中使用IF OR Else
Using IF OR Else in Java Script
我目前正在为我的游戏社区制作一个网站,我制作的网站看起来像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") {
相关文章:
- 在Javascript中为if/else语句添加OR
- 在JavaScript / jQuery中,是否有一种更短的方法可以编写在同一个测试变量上具有许多OR的“if”语句
- javascript确定触发if语句的OR语句
- if语句上的Javascript OR
- Javascript if else语句OR条件错误
- Javascript If Condition with multiple OR and AND
- if 语句中多个 OR 表达式的简写
- JavaScript 中的 if 和 or 子句
- Javascript Multiple OR 在 if 条件下使用 for 循环
- Javascript if else 语句带有 OR 和 IS NOT
- 我应该使用 if-then-else 或 and or 运算符来检查 Javascript 中的空值吗?
- 可以 And and and or 替换 if()
- 在 JavaScript 中,在继续之前执行具有多个 or 的 if 评估所有语句
- 如何使用||(OR)编写重复次数较少的if语句
- JS HTML conditions if else or switch
- 对同一变量使用多个OR条件来简化IF语句
- 在 Javascript 中返回 'if' 语句与逻辑 OR
- ember if or statement
- 在Java脚本中使用IF OR Else
- 检查IF/OR中的多个条件,并且是EMPTY Javascript