HTML网页计算器No1:!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==Content-Typecontent=text/html;charset=gb2312/title无标题文档/titlescriptlanguage=javascriptfunctionjsq(fh){varnum1,num2;num1=parseFloat(document.form1.text1.value);num2=parseFloat(document.form1.text2.value);if(fh==+)document.form1.text3.value=num1+num2;if(fh==-)document.form1.text3.value=num1-num2;if(fh==*)document.form1.text3.value=num1*num2;if(fh==/)if(num2!=0){document.form1.text3.value=num1/num2;}else{alert(除数不能为零!)}}/script/headbodyformid=form1name=form1method=postaction=labelinputname=text1type=textid=text1//labelplabelinputname=text2type=textid=text2//label/pplabelinputname=Button1type=Buttonid=Button1value=+onClick=jsq('+')inputname=Button2type=Buttonid=Button2value=-onClick=jsq('-')/inputname=Button3type=Buttonid=Button3value=*onClick=jsq('*')/inputname=Button4type=Buttonid=Button4value=/onClick=jsq('/')//label/pplabelinputname=text3type=textid=text3//label/p/form/body/html第二种:htmlheadMETAhttp-equiv=Content-Typecontent=text/html;charset=gb2312title计算器/titlestyletype=text/cssbody{background-color:pink;}table{border-left:1#FFFFFFsolid;border-top:1#FFFFFFsolid;}.input1{border-right:#FFFFFF1pxsolid;border-top:#0000001pxsolid;border-left:#0000001pxsolid;border-bottom:#FFFFFF1pxsolid;width:180px;background-color:#FFFFFF;text-align:right;}input{border-right:#0000001pxsolid;BORDER-TOP:#ffffff1pxsolid;border-left:#ffffff1pxsolid;color:#000080;border-bottom:#0000001pxsolid;background-COLOR:#d8d8d0;width:40px;height:20px;}td{border-bottom:#FFFFFF1solid;border-right:#FFFFFF1solid;height:25px;}/stylescriptlanguage=javascriptvartotal=0;//全局变量total,累计输入varFlagNew=false;//是否是新的操作数(输入的第二个数)varOpp=;//运算符变量functionclearall(){total=0;document.myform.number.value=0;//清除结果}functionenternumber(Num){//数字按钮单击调用的函数,Num表示输入的数字if(FlagNew){//判断输入的是否新的操作数document.myform.number.value=Num;FlagNew=false;}else{if(document.myform.number.value==0)document.myform.number.value=Num;elsedocument.myform.number.value+=Num;//记录输入的操作数}}functionOperation(Op){//“加减乘除”按钮单击调用的函数,Op代表运算符号varNum1=document.myform.number.value;if(FlagNew&&Opp!==);{FlagNew=true;//根据运算符进行运算if('+'==Opp)total+=parseFloat(Num1);elseif('-'==Opp)total-=parseFloat(Num1);elseif('/'==Opp)total/=parseFloat(Num1);elseif('*'==Opp)total*=parseFloat(Num1);else{total=parseFloat(Num1);}document.myform.number.value=total;//结果文本框累计数字Opp=Op;}}/script/headbodyh3align=center计算器/h1tablewidth=180border=0cellspacing=0cellpadding=3align=centerformaction=method=postname=myformtrtdcolspan=4inputname=numbertype=textclass=input1value=0/td/trtrtdinputname=number7type=buttonvalue=7onClick=enternumber(7)/tdtdinputname=number8type=buttonvalue=8onClick=enternumber(8)/tdtdinputname=number9type=buttonvalue=9onClick=enternumber(9)/tdtdinputname=number+type=buttonvalue=+onClick=Operation('+')/td/trtrtdinputname=number4type=buttonvalue=4onClick=enternumber(4)/tdtdinputname=number5type=buttonvalue=5onClick=enternumber(5)/tdtdinputname=number6type=buttonvalue=6onClick=enternumber(6)/tdtdinputname=number-type=buttonvalue=-onClick=Operation('-')/td/trtrtdinputname=number1type=buttonvalue=1onClick=enternumber(1)/tdtdinputname=number2type=buttonvalue=2onClick=enternumber(2)/tdtdinputname=number3type=buttonvalue=3onClick=enternumber(3)/tdtdinputname=number*type=buttonvalue=*onClick=Operation('*')/td/trtrtdinputname=number0type=buttonvalue=0onClick=enternumber(0)/tdtdinputname=numberCtype=buttonvalue=ConClick=clearall();/tdtdinputname=number=type=buttonvalue==onClick=Operation('=')/tdtdinputname=number/type=buttonvalue=/onClick=Operation('/')/td/form/table/body/html第三种:!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN==Content-Typecontent=text/html;charset=gb2312/title计算器/titlescriptlanguage=javascriptfunctionjsq(form){varnum1,num2,fh;num1=parseFloat(document.form1.text1.value);num2=parseFloat(document.form1.text2.value);fh=document.form1.fh.value;if(fh==1){document.form1.text3.value=num1+num2;}elseif(fh==2)document.form1.text3.value=num1-num2;elseif(fh==3)document.form1.text3.value=num1*num2;elseif(fh==4)if(num2!=0){document.form1.text3.value=num1/num2;}else{alert(除数不能为零!)}}/script/headbodyformid=form1name=form1labelinputtype=textname=text1//labellabelselectid=select1name=fhoptionvalue=1+/optionoptionvalue=2-/optionoptionvalue=3*/optionoptionvalue=4//option/select/labellabelinputtype=textname=text2//labellabelinputtype=buttonname=btnvalue==onclick=jsq(form1)//labellabelinputtype=textname=text3//label/form/body/html