JS计算器

作者: 潘某i人 | 来源:发表于2018-04-12 11:38 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>计算器</title>
        <script type="text/javascript">
            window.onload = function(){
                var oX = document.getElementById("x");
                var oSe = document.getElementById("se");
                var oY = document.getElementById("y");
                var oBt1 = document.getElementById("bt1");
                oBt1.onclick=jS;
                function jS(){
                    var oSee = oSe.value;
                    var ovalue1 = oX.value;
                    var ovalue2 = oY.value;
                    if (ovalue1 =="" || ovalue2 == "") {
                        alert("不能为空")
                    }else if (isNaN(ovalue1) || isNaN(ovalue2)) {
                        alert("请输入数字!")
                    }else{
                        if (oSee == "+") {
                            alert(((parseFloat(ovalue1)*100)+(parseFloat(ovalue2)*100))/100);
                        }else if (oSee == "-") {
                            alert(((parseFloat(ovalue1)*100)-(parseFloat(ovalue2)*100))/100);
                        }else if (oSee == "*") {
                            alert(((parseFloat(ovalue1)*100)*(parseFloat(ovalue2)*100))/10000);
                        }else if (oSee == "/") {
                            alert((parseFloat(ovalue1)*100)/(parseFloat(ovalue2)*100));
                    }
                    }
                    
                }
            }
            
    
        </script>
    </head>
    <body>
        <h1 class="bt">计算器</h1>
        <div class="bd">
            <input type="text" id="x">
            <select name="" id="se">
                <option value="+">+</option>
                <option value="-">-</option>
                <option value="*">*</option>
                <option value="/">/</option>
            </select>
            <!-- <input type="select" class="xy"> -->
            <input type="text" id="y">
            <button id="bt1">计算</button>
        </div>
    </body>
    </html>
    
    image.png image.png image.png image.png image.png image.png

    相关文章

      网友评论

        本文标题:JS计算器

        本文链接:https://www.haomeiwen.com/subject/ojjxkftx.html