有人可以帮我吗?应该发生的是,它应该让用户的名字,姓氏和组成号码多于3,再减去1000。将其显示在网页上,如果名字+姓氏少于20,则组成号码大于3小于1000,则该功能将启动,如果无效,则提醒用户。
<!DOCTYPE html>
<!--Jeffrey Payne-->
<html>
<head>
<title>UAT Space Program</title>
</head>
<body>
<img src="UATSpace.png" />
<h1>UAT Space Program</h1>
<p>Test of the paragraph tags</p>
<input type="text" id="input"/>
<input type="text" id="input2"/>
<input type="text" id="input3"/>
<button type="button" onclick="start()">Start</button>
<script>
function startLoop(){
var currTime = 50;
for(i=50; i>=0; i=i-5) {
setTimeout(function(){
if(currTime != 0){
document.write("Time remaining: " + currTime + "<br>");
}
if (currTime <= 25 && currTime!=0){
document.write("less then 25 seconds left <br>");y
} else if(currTime==0){
document.write("blast off");
}
currTime = currTime - 5;
}, 1000*i);
}
}
function start(){
var vari = document.getElementById(input).value;
var vari2 = document.getElementById(input2).value;
var badge = document.getElementById(input3).value;
document.write(vari + vari2);
document.write(badge);
var sum = vari + vari2;
if(sum < 20){
if(badge > 3 && badge < 1000){
startLoop();
}else {
alert("Please re-enter your badge number");
}
} else {
alert("Please re-enter your name")
}
}
</script>
</body>
</html>
您在创建逻辑时处于正确的轨道。调试时,请尝试使用网络浏览器的控制台,看看出了什么问题。在您的情况下,您的document.getElementById('input').value;
代码缺少引号。另外,如果您想知道字符串的长度,请使用.length
属性,因为例如使用vari + vari2
会导致字符串被组合/串联。