js计算器

来源:互联网 发布:当女程序员遇到问题时 编辑:程序博客网 时间:2024/05/16 05:48

 

 <script type="text/javascript">
        var f;
        var fuhao;
     

        function out(num) {
            document.getElementById("txtword").value += num;// 吧相应的数字显示在文本框中
           
        }

        function outer(fu) {    //返回相应的运算符号,用以在等号里判断
           
          
            f = document.getElementById("txtword").value;
            document.getElementById("txtword").value = "";
            fuhao = fu;
            return fuhao;

 

        }
        function clear1() {                              //  清除所有数据!

            document.getElementById("txtword").value = "";

        }
        function subss() {

            var t = document.getElementById("txtword");
            t.value = t.value.substring(0, t.value.length - 1);
        }

        function equal()  {              //等号里的判断!
        


            if (fuhao == '+') {

                document.getElementById("txtword").value = parseFloat(f) + parseFloat(document.getElementById("txtword").value);
            }
            else if (fuhao == '-') {
                document.getElementById("txtword").value = parseFloat(f) - parseFloat(document.getElementById("txtword").value);

            }
            else if (fuhao == '*') {
                document.getElementById("txtword").value = parseFloat(f) * parseFloat(document.getElementById("txtword").value);

            }
            else if (fuhao == '/') {
                document.getElementById("txtword").value = parseFloat(f) /parseFloat(document.getElementById("txtword").value);
            }
          
       
       
        }
   
    </script>

原创粉丝点击