我一直在尝试创建一个if语句,如果输入框中输入了特定的字符串,则返回一条消息。
var ram = 0;
var run = document.getElementById('run');
var r = function() {
ram++;
if (ram == 1) {
var ib = document.getElementById("ib").value + ": logged in type smash to begin hacking";
var node = document.createElement("li");
var textnode = document.createTextNode(ib);
node.appendChild(textnode);
document.getElementById("log2").appendChild(node);
} else
if (ib.value == "smash" && ram == 2) {
var node2 = document.createElement("li");
var textnode2 = document.createTextNode("smash:entering malware_on3........making alias .....guest accessesing guest...done:)");
node2.appendChild(textnode2);
document.getElementById("log2").appendChild(node2);
}
run.addEventListener("click", r);
}
答案 0 :(得分:2)
var inputBoxElement = document.getElementById("myInputBox");
if( inputBoxElement.value == "~some string~" ){
//however you'd like to notify your users
}
不确定这是否是您正在寻找的......
答案 1 :(得分:1)
你需要做的是在第一个if语句之外选择ib,这样它就可以用在第二个if语句中:
var ram = 0;
var run = document.getElementById('run');
var r = function() {
ram++;
var ib = document.getElementById("ib");
if (ram == 1) {
var node = document.createElement("li");
var textnode = document.createTextNode(ib.value + ": logged in type smash to begin hacking");
node.appendChild(textnode);
document.getElementById("log2").appendChild(node);
} else if (ib.value == "smash" && ram == 2) {
var node2 = document.createElement("li");
var textnode2 = document.createTextNode("smash:entering malware_on3........making alias .....guest accessesing guest...done:)");
node2.appendChild(textnode2);
document.getElementById("log2").appendChild(node2);
}
}
run.addEventListener("click", r);