📄 计算器.txt
字号:
<html><head>
<script language="JavaScript">
<!--
//定义全局变量
var n1='',n2=''; //定义两个变量,分别存放两个操作数
var item1_flag=true; //标志是否第一个操作数
var opr_type='+'; //运算类型
function SetVal(item){ //在输入框中置数值
document.Cal.OutText.value+=item; //字符串连接
if (item1_flag) //若是第一个操作数
n1+=item; //将其加入变量n1
else
n2+=item;
}
function SetOpr(opr){ //在输入框中置运算符
document.Cal.OutText.value+=opr;
item1_flag=false;
opr_type=opr;
}
function Clear( ){ //清除输入框的内容
document.Cal.OutText.value="";
item1_flag=true; opr_type='+'; n1=" "; n2=" ";
}
function Compute(obj){ //计算表达式的值
var Result;
if ((n1!='') && (n2!='')){
if ((eval(n2)==0) && (opr_type=='/'))
{ alert('除数不能是0!');
Clear( );
return;
}
else
{
Result=eval(obj.OutText.value);
document.Cal.OutText.value+='=';
document.Cal.OutText.value+=Result;
}
}
}
//-->
</script></head>
<body><p align=center><form name="Cal" >
<input type="text" value="" name="OutText"><br><br>
<input type="button" value=" 0 " onClick="SetVal('0')">
<input type="button" value=" 1 " onClick="SetVal('1')">
<input type="button" value=" 2 " onClick="SetVal('2')">
<input type="button" value=" 3 " onClick="SetVal('3')"><br><br>
<input type="button" value=" 4 " onClick="SetVal('4')">
<input type="button" value=" 5 " onClick="SetVal('5')">
<input type="button" value=" 6 " onClick="SetVal('6')">
<input type="button" value=" 7 " onClick="SetVal('7')"><br><br>
<input type="button" value=" 8 " onClick="SetVal('8')">
<input type="button" value=" 9 " onClick="SetVal('9')">
<input type="button" value=" + " onClick="SetOpr('+')">
<input type="button" value=" ? " onClick="SetOpr('?')"><br><br>
<input type="button" value=" * " onClick="SetOpr('*')">
<input type="button" value=" / " onClick="SetOpr('/')">
<input type="button" value=" CE " onClick="Clear()">
<input type="button" value=" = " onClick="Compute(this.form)">
</form></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -