• 网页计算器

    <!DOCTYPE html> html> <head> <title>计算器</title> <script type="text/javascript"> //键盘事件,文本锁定,限制键盘输入的范围 function append0(){ document.form1.data.value+=document.form1.v0.value; } function append1(){ document.form1.data.value+=document.form1.v1.value; } function append2(){ document.form1.data.value+=document.form1.v2.value; } function append3(){ document.form1.data.value+=document.form1.v3.value; } function append4(){ document.form1.data.value+=document.form1.v4.value; } function append5(){ document.form1.data.value+=document.form1.v5.value; } function append6(){ document.form1.data.value+=document.form1.v6.value; } function append7(){ document.form1.data.value+=document.form1.v7.value; } function append8(){ document.form1.data.value+=document.form1.v8.value; } function append9(){ document.form1.data.value+=document.form1.v9.value; } function appendd(){ var v=document.form1.data.value; if(isHave(v)){ document.form1.data.value+=document.form1.vd.value; }else{ appende(); } } function appendm(){ var v=document.form1.data.value; if(isHave(v)){ document.form1.data.value+=document.form1.vm.value; }else{ appende(); } } function appendc(){ var v=document.form1.data.value; if(isHave(v)){ document.form1.data.value+=document.form1.vc.value; }else{ appende(); } } function appendp(){ var v=document.form1.data.value; if(isHave(v)){ document.form1.data.value+=document.form1.vp.value; }else{ appende(); } } function appendpo(){ document.form1.data.value+=document.form1.vpo.value; } function appende(){ var str_value=document.form1.data.value; var num0,num1; if(str_value.indexOf("-")==0){ var substr=str_value.substring(1,str_value.length); var arr=substr.split("-"); _four(substr,num0,num1); } four(str_value,num0,num1); function four(str_value,num0,num1){ if(str_value.indexOf("-")>0){ var arr=str_value.split("-"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=num0-num1; }else if(str_value.indexOf("+")>0){ var arr=str_value.split("+"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=num0+num1; }else if(str_value.indexOf("X")>0){ var arr=str_value.split("X"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=num0*num1; }else if(str_value.indexOf("/")>0){ var arr=str_value.split("/"); num0=arr[0]*1; num1=arr[1]*1; if(num1==0){ document.form1.data.value="除数不能为零"; }else{ document.form1.data.value=num0/num1; } } } function _four(str_value,num0,num1){ if(str_value.indexOf("-")>0){ var arr=str_value.split("-"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=-num0-num1; }else if(str_value.indexOf("+")>0){ var arr=str_value.split("+"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=-num0+num1; }else if(str_value.indexOf("*")>0){ var arr=str_value.split("*"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=-num0*num1; }else if(str_value.indexOf("/")>0){ var arr=str_value.split("/"); num0=arr[0]*1; num1=arr[1]*1; document.form1.data.value=-num0/num1; } } } function appendsqrt(){ var v=document.form1.data.value; if(v>=0){ document.form1.data.value=Math.sqrt(v); }else{ document.form1.data.value="开方数不能为负"; } } function appendpercent(){ var v=document.form1.data.value; if(v>0 && v<1){ document.form1.data.value=v*100+"%"; }else{ document.form1.data.value="不能为整数"; } } function appendfraction(){ var v=document.form1.data.value; if(v==0){ document.form1.data.value="除数不能为零"; }else{ document.form1.data.value=1/v; } } function appendclear(){ document.form1.data.value=""; } function isHave(c){ if(c.indexOf("+")>0||c.indexOf("-")>0||c.indexOf("*")>0||c.indexOf("/")>0){ return false; }else{ return true; } } </script> </head> <body bgcolor="#C8E0D8"> <center> <h4 style="font-size:45px;width:375px;height:40px;color:red">自制计算器</h4> <form name="form1" method="post"> <table border="5"> <tr> <input type="text" name="data" style="font-size:30px;width:375px;height:65px;color:black;background:pink" disabled="disabled"/> </tr> <tr> <td align="center" ><input name="v7" style="font-size:30px;width:65px;height:65px;color:blue;background:green" type="button" value="7" onclick="append7();" style="width:50px"/></td> <td align="center"><input name="v8" style="font-size:30px;width:65px;height:65px;color:blue;background:gold" type="button" value="8" onclick="append8();" style="width:50px"/></td> <td align="center"><input name="v9" style="font-size:30px;width:65px;height:65px;color:blue;background:pink" type="button" value="9" onclick="append9();" style="width:50px"/></td> <td align="center"><input name="vd" style="font-size:30px;width:65px;height:65px;color:blue;background:brown" type="button" value="/" onclick="appendd();" style="width:50px"/></td> <td align="center"><input style="font-size:30px;width:75px;height:65px;color:rubine;background:red" type="button" value="清除" onclick="appendclear();" style="width:62px"/></td> </tr> <tr> <td align="center"><input name="v4" style="font-size:30px;width:65px;height:65px;color:blue;background:greenyellow" type="button" value="4" onclick="append4();" style="width:50px"/></td> <td align="center"><input name="v5" style="font-size:30px;width:65px;height:65px;color:blue;background:khaki" type="button" value="5" onclick="append5();" style="width:50px"/></td> <td align="center"><input name="v6" style="font-size:30px;width:65px;height:65px;color:blue;background:chocolate" type="button" value="6" onclick="append6();" style="width:50px"/></td> <td align="center"><input name="vm" style="font-size:30px;width:65px;height:65px;color:blue;background:cyan" type="button" value="X" onclick="appendm();" style="width:50px"/></td> <td align="center"><input style="font-size:30px;width:75px;height:65px;color:blue" type="button" value="%" onclick="appendpercent();" style="width:62px"/></td> </tr> <tr> <td align="center"><input name="v1" style="font-size:30px;width:65px;height:65px;color:blue;background:coral" type="button" value="1" onclick="append1();" style="width:50px"/></td> <td align="center"><input name="v2" style="font-size:30px;width:65px;height:65px;color:blue;background:darkviolet" type="button" value="2" onclick="append2();" style="width:50px"/></td> <td align="center"><input name="v3" style="font-size:30px;width:65px;height:65px;color:blue;background:bisque" type="button" value="3" onclick="append3();" style="width:50px"/></td> <td align="center"><input name="vc" style="font-size:30px;width:65px;height:65px;color:blue;background:salmon" type="button" value="-" onclick="appendc();" style="width:50px"/></td> <td align="center"><input style="font-size:30px;width:75px;height:65px;color:blue;background:Tan" type="button" value="1/x" onclick="appendfraction();" style="width:62px"/></td> </tr> <tr> <td align="center"><input name="v0" style="font-size:30px;width:65px;height:65px;color:blue;background:teal" type="button" value="0" onclick="append0();" style="width:50px"/></td> <td align="center"><input name="vpo" style="font-size:30px;width:65px;height:65px;color:blue;background:aquamarine" type="button" value="." onclick="appendpo();" style="width:50px"/></td> <td align="center"><input name="ve" style="font-size:30px;width:65px;height:65px;color:blue;background:peru" type="button" value="=" onclick="appende();" style="width:50px"/></td> <td align="center"><input name="vp" style="font-size:30px;width:65px;height:65px;color:blue;background:plum" type="button" value="+" onclick="appendp();" style="width:50px"/></td> <td align="center"><input style="font-size:30px;width:75px;height:65px;color:blue;background:rosybrown"type="button" value="√x" onclick="appendsqrt();" style="width:62px"/></td> </tr> </table> <h4 style="font-size:20px;width:375px;height:40px;color:blue">开发者:赵海瑞||电话13848828417<br>时间:2015年4月10日</h4> </form> </center> </body> </html>

    0
    112
    9KB
    2015-06-01
    10
  • 万能javaDAO

    自己写的万能DAO 可连任何数据库 实现增 删 改 查

    0
    156
    447KB
    2014-07-11
    16
  • JAVA 图片上传 预览

    JAVA 图片上传 预览 实现代码

    4
    190
    2.52MB
    2014-07-05
    16
关注 私信
上传资源赚积分or赚钱