用javascript编写加减乘除的计算器
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN"><HTML><HEAD><TITLE>计算器</TITLE...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 计算器 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript" type="text/javascript">
function jisuan(){
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = "";
if (NaN(number1) == true || NaN(number2) == true)
{
number4 = NaN;
}
else{
if (array3 == "+" )
{
txtnum = number1 + number2;
}
if (array3 == "-")
{
txtnum = number1 - number;
}
if (array3 == "*")
{
txtnum = number1 * number2;
}
if (array3 == "/")
{
if (number2 == 0)
{
alert("除数不能为0!请重新输入");
}
else{
txtnum = number1 / number2;
}
}
}
}
</script>
</HEAD>
<BODY>
<form name=form1>
<input type=text name=num1 value="">
<input type=text name=num2 value="" size=2>
<input type=text name=arr3 value="">
<input type="button" name=arr value="=" onclick="return jisuan()">
<input type=text name=num4 value="">
</form>
</BODY>
</HTML>
查看网页的时候说缺少函数 为什么?
前面的
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = "";
改成
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = number4; 展开
<HTML>
<HEAD>
<TITLE> 计算器 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="JavaScript" type="text/javascript">
function jisuan(){
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = "";
if (NaN(number1) == true || NaN(number2) == true)
{
number4 = NaN;
}
else{
if (array3 == "+" )
{
txtnum = number1 + number2;
}
if (array3 == "-")
{
txtnum = number1 - number;
}
if (array3 == "*")
{
txtnum = number1 * number2;
}
if (array3 == "/")
{
if (number2 == 0)
{
alert("除数不能为0!请重新输入");
}
else{
txtnum = number1 / number2;
}
}
}
}
</script>
</HEAD>
<BODY>
<form name=form1>
<input type=text name=num1 value="">
<input type=text name=num2 value="" size=2>
<input type=text name=arr3 value="">
<input type="button" name=arr value="=" onclick="return jisuan()">
<input type=text name=num4 value="">
</form>
</BODY>
</HTML>
查看网页的时候说缺少函数 为什么?
前面的
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = "";
改成
var number1 = document.form1.num1.value;
var number2 = document.form1.num2.value;
var array3 = document.form1.arr3.value;
var number4 = document.form1.num4.value;
var txtnum = number4; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询