1.变量名、函数名、表单控件(对象)名字命名随意,容易重复;
2.多个函数一同调试。最好调试通过完一个函数再去编写下一个,不建议全部完成,否则不好找到问题所在;
3.在eclipse中创建网页文件是在Webcontent里创建,不是在其下的WEB-INF中创建,否则文件找不到;
4.表单、控件不起名就想访问。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script>
function start1(){
var i;
var a=Math.round(parseInt(Math.random()*100));
var b=Math.round(parseInt(Math.random()*100));
var c=Math.round(parseInt(Math.random()*2));//0-2 ≥0 <2 故只产生0 1
alert(c);
if(c==0)
app.sign.value="+";
else
app.sign.value="-";
app.num1.value=a;
app.num2.value=b;
}
function judge(){
if(app.sign.value=="+"){
if(parseInt(app.num3.value)==parseInt(app.num1.value)+parseInt(app.num2.value)){
alert("Correct");
}
else
alert("Wrong");
}
else if(app.sign.value=="-"){
if(parseInt(app.num3.value)==parseInt(app.num1.value)-parseInt(app.num2.value)){
alert("Correct");
}
else
alert("Wrong");
}
}
</script>
</head>
<body>
<form name="app">
<p>ADD&SUB</p>
<input type="button" value=start onClick=start1()><br></br>
<input type="text" name="num1" >
<input type="text" name="sign" size="1">
<input type="text" name="num2"> =
<input type="text" name="num3" > <br></br>
<input type="button" value=submmit onClick=judge()>
</form>
</body>
</html>