下面的代码。有逻辑错误,我是在fontpage2000中弄的。怎么运算结果都不正确,输入数后,总提示一个要不都是”恭喜“错了也提示“恭喜”。请把这段代码弄到fontpage2000中测试。<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="JavaScript">
function aa()
{
var x=t1.value;
var y=t2.value;
var z=t3.value;
if(x+y==z)
alert("恭喜你!")
else
alert("抱歉!")
}
</script> </head><body>
<input type="text" name="t1" size=8>+
<input type="text" name="t2" size=8>=
<input type="text" name="t3" size=12>
<input type="button" name="t4" value="检查结果" onclick="aa();">
</body>
</html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language="JavaScript">
function aa()
{
var x=t1.value;
var y=t2.value;
var z=t3.value;
if(x+y==z)
alert("恭喜你!")
else
alert("抱歉!")
}
</script> </head><body>
<input type="text" name="t1" size=8>+
<input type="text" name="t2" size=8>=
<input type="text" name="t3" size=12>
<input type="button" name="t4" value="检查结果" onclick="aa();">
</body>
</html>
if you input 1 to t1
2 to t2
So x+y in the function aa() is 12 not 3.
surely prints 抱歉!You should change the
var x=t1.value;
var y=t2.value;
var z=t3.value;
to number!
text类型的域是字符类型,转换成数字后方可运算