gpt4 book ai didi

Javascript 代码在函数内部时不运行

转载 作者:行者123 更新时间:2023-12-03 06:30:21 25 4
gpt4 key购买 nike

我正在用 html 和 javascript 制作游戏,并使用“控制台”,我使用 IF 语句来允许用户在游戏中导航。但是,他们似乎停止了工作。它们允许用户在游戏中移动。为什么 IF 语句没有运行以及如何解决这个问题?

function runcmd(){
var user = document.getElementById('code').value;
if(user == 'clear'){
l1.innerHTML = '';
l2.innerHTML = '';
l3.innerHTML = '';
l4.innerHTML = '';
l5.innerHTML = '';
l6.innerHTML = '';
l7.innerHTML = '';
l8.innerHTML = '';
l9.innerHTML = '';
l10.innerHTML = '';
};
if(user == 'connect'){
var user = document.getElementById('code').value;
l1.innerHTML = 'Connecting to ' ;
l2.innerHTML = 'Connected to ' ;
connected = true;
l4.innerHTML = 'view bank';
l5.innerHTML = 'upload [virus]';
l8.innerHTML = 'disconnect [ip]';
if(user == 'disconnect'){
connected = false;
l1.innerHTml = 'Disconnected Safely...';
};
if(user == 'view bank'){
var pwrd = Math.floor( Math.random() * 1) - 10000;
var nam = Math.floor( Math.random() * 1) - 10000;
alert(pwrd);
alert(nam);
var uname = 'user' + nam;
var user = prompt('Username: ');
var pass = prompt('Password: ');
if(user == uname && pass == pwrd ){
}
};
if(user == 'upload'){
svirus= prompt('Enter Virus: ');
for(var key in boughtviruses) {
if(boughtviruses[key] == svirus) {
l1.innerHTML = 'Uploading ' + svirus;
l2.innerHTML = 'Virus Uploaded';
}else{
alert("You Don't Have This Virus!");
};
};
};
};
};
			.console{
position: relative;
height: 250px;
width: 500px;
background-color: #000;
border-left: 10px solid #cccccc;
border-top: 5px solid #cccccc;
border-right: 10px solid #cccccc;
border-bottom: 10px solid #cccccc;
}
.exit {
float: right;
background: #800000;
color: white;
height: 25px;
border: none;
width: 40px;
font-size: 20px;
text-align: center;
margin-left: 5px;
}
			<div id="con" class="console">
<button class="exit" onclick="hidecon()">X</button>
<span class="span" id="l1" style="width:50px"></span><br />
<span class="span" id="l2" style="width:50px"></span><br />
<span class="span" id="l3" style="width:50px"></span><br />
<span class="span" id="l4" style="width:50px"></span><br />
<span class="span" id="l5" style="width:50px"></span><br />
<span class="span" id="l6" style="width:50px"></span><br />
<span class="span" id="l7" style="width:50px"></span><br />
<span class="span" id="l8" style="width:50px"></span><br />
<span class="span" id="l9" style="width:50px"></span><br />
<span class="span" id="l10" style="width:50px"></span><br />
<span style="position: absolute; left: 0; bottom: 0;color:#66ff33;">C:\></span><input onclick="this.select()" id="code" class="inp"/>
<button style="border:none;position:absolute;background-color:black;bottom:0;right:114;color:#66ff33;border-radius: 5px;border: 1px solid white;" onclick="runcmd()">Send Command</button>
</div>

最佳答案

当您输入“-10000”作为密码和“user-10000”作为用户名时,工作正常

关于Javascript 代码在函数内部时不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com