现在一年级小学生需要练习大量的加减法。这是用html 写的一个小程序。希望对大家有所帮助。
<!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>