简体   繁体   English

Javascript科学计算器输入错误

[英]aJavascript scientific calculator input error

Working on a calculator with basic sin and cosine functions. 使用具有基本正弦和余弦函数的计算器。

Code in jsfiddle: http://jsfiddle.net/C9VcE/ jsfiddle中的代码: http : //jsfiddle.net/C9VcE/

Getting an error where I can only enter one character for the input. 出现错误,我只能输入一个字符作为输入。

Also currently sin function 目前还具有sin功能

function call_func(sin) {
        output=Number (numberone, numbertwo)
        document.getElementById('equation').value =output; 
    }

seems to have issues where until I press 'Clear" the calculator won't change values. 似乎有个问题,直到我按“清除”,计算器才会更改值。

Thanks in advance. 提前致谢。

The problem with your code lies in the getnumber function definition. 代码的问题在于getnumber函数定义。

Please change the code as specified below and give a try. 请按照下面的指定更改代码,然后尝试。

function getnumber (number) {
            var val = document.getElementById('equation').value;
            document.getElementById('equation').value = val.toString() + number;

            if(numberone=="") {
                numberone=number;
            /*document.getElementById('equation').value =numbertwo; */
            } else {
                numbertwo=number;
            /*document.getElementById('equation').value =numberone; */
            }

        }

I've seen your code. 我看过您的代码。 You need to put this line 你需要把这行

document.getElementById('equation').value =document.getElementById('equation').value+number; 

But then you need to trim and convert this string to number correctly 但是,然后您需要修剪并将此字符串正确转换为数字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM