首页 > 代码库 > 简易计算器

简易计算器

<!doctype html><html><head><meta charset="utf-8"><meta name="author" ><meta name="copyright"<title></title><script>window.onload=function (){    var oTxt1=document.getElementById(txt1);        var oTxt2=document.getElementById(txt2);        var oBtn=document.getElementById(btn);        var oSel=document.getElementById(sel1);        oBtn.onclick=function (){        var _n1=oTxt1.value;        var _n2=oTxt2.value;        var n1=oTxt1.value-0;        var n2=oTxt2.value-0;        var str=oSel.value;        if(_n1==‘‘|| _n2==‘‘)        {            alert(请输入);        }        else if(isNaN(n1)||isNaN(n2))        {            alert(至少一个不是数字);        }        else        {            switch(str)            {                case +:                alert(n1+n2);                break;                case -:                alert(n1-n2);                break;                case *:                alert(n1*n2);                break;                case -:                alert(n1-n2);                break;            }                    }    };};</script></head><body>    <input type="text" id="txt1" />    <select id="sel1">        <option value="+">+</option>        <option value="-">-</option>        <option value="*">*</option>        <option value="/">/</option>    </select>    <input type="text" id="txt2" />        <input type="button" value="计算" id="btn" /></body></html>

 

简易计算器