3 回答
TA贡献245条经验 获得超106个赞
代码如下:
<html>
<head>
<title>低B计算器</title>
<script language="javascript" type="text/javascript">
var a;
function t(){
var num1=parseFloat(document.form1.textfield.value);
var num2=parseFloat(document.form1.textfield2.value);
var result;
switch(a){
case "1":result=num1+num2;document.form1.textfield3.value=result;a="0";break;
case "2":result=num1-num2;document.form1.textfield3.value=result;a="0";break;
case "3":result=num1*num2;document.form1.textfield3.value=result;a="0";break;
case "4":result=num1/num2;document.form1.textfield3.value=result;a="0";break;
default:document.form1.textfield3.value=("请问您要执行哪种运算?");break;
}
}
function plus(){
a="1";
}
function subtract(){
a="2";
}
function multiply(){
a="3";
}
function divide(){
a="4";
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="textfield" id="textfield" />
<br />
<input type="button" name="button" id="button" value="+" onclick="plus()"/>
<input type="button" name="button2" id="button2" value="-" onclick="subtract()"/>
<input type="button" name="button3" id="button3" value="*" onclick="multiply()"/>
<input type="button" name="button4" id="button4" value="/" onclick="divide()"/>
<br />
</label>
<label>
<input type="text" name="textfield2" id="textfield2" />
<br />
<input type="button" name="button5" id="button5" value="=" onclick="t()"/>
<br />
</label>
<label>
<input type="text" name="textfield3" id="textfield3" />
<br />
</label>
</form>
</body>
</html>
代码在网页上格式都破坏了,需要你重新格式化,希望对你有帮助,有其他问题还可以继续问我哦
添加回答
举报