weixin_33708432 2014-12-12 23:40 采纳率: 0%
浏览 29

可存储2个变量的函数

I need to do a calculator and assume I have to click button to insert number to display box. For example click 3 and 2 the inputbox display 32 than i need to click "+" button. The add button is to remove the previous number and store it so that i can retype a new number(like a normal calculator do). After that I need to store 3 objects. Which is first input number, "+" and the second number. The reason of store those object is because i need to create the "=" button to send those number to php.

What i need to do and do i need to modify the code. P.S I m using ajax for the "=" function and send it to php. However, I didn't create it yet.

var memory = "";
    $("#add").click(function() {
                memory += $show.val() + "+";
                $show.val("");
            });
  • 写回答

1条回答 默认 最新

  • weixin_33691700 2014-12-12 23:50
    关注

    You could store the variables as an object, or array.

    var memory = {
     var1: 123,
     var2: 123
    }
    

    or

    var memory = [var1, var2];
    

    then you can grab either one when you need it.

    评论

报告相同问题?