numerical value of number input by user in a text field

后端 未结 4 1244
灰色年华
灰色年华 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:07

    Number() is the function you want "123a" returns NAN

    parseInt() truncates trailing letters "123a" returns 123

    
    
    • jsfiddle

提交回复
热议问题