numerical value of number input by user in a text field

后端 未结 4 1231
灰色年华
灰色年华 2020-12-06 19:47

I need to add up two numbers input by the user. To do that, I create two input fields, retrieve values from them , using .val(), in two separate variables and then add them.

4条回答
  •  囚心锁ツ
    2020-12-06 20:17

    You can use parseInt(...)

    Example:

    var num = parseInt("2", 10) + parseInt("3", 10);
    // num == 5
    

提交回复
热议问题