0

I am making a calculator just for fun to learn about Javascript (I know HTML & CSS very well)and I have the basis of the calculator made. I wanted to make it so that you just use the buttons. The buttons work and all. But for example if I wanted to insert 11, that wouldn't be possible because I can only insert single digits and I don't know why :( Here is the button you press to insert the number 1.

<button type="button" onclick="no1 ()">1</button>

This is the javascript to insert he number 1 into the input tag:

var currentinput= document.getElementById("firstnumber");

var answer= document.getElementById("answer");
function no1 ()
{
currentinput.value=1;
answer.value=1;
}

How would I able to insert 11 instead of just 1?

4

1 回答 1

0

如果你想在变量的末尾添加一些东西,你可以使用这样的东西:

function no1 ()
{
    currentinput.value = currentinput.value+"1";
    answer.value=1;
}

这将采用 currentinput.value 中已有的数字并在末尾添加 1。

于 2013-10-10T17:00:41.400 回答