Why does this concatenate instead of adding up

后端 未结 3 613
夕颜
夕颜 2020-12-12 05:04

Very very basic question but I\'ve got the following HTML:




        
3条回答
  •  眼角桃花
    2020-12-12 05:44

    Do I need to use parseInt or something?

    Exactly. val() will return strings, which will get concatenated and not added up.

    Do note that when using parseInt you should supply the radix parameter (second one) for the correct base - 10 for decimal, otherwise it will assume octal.

    one = parseInt( $('#nspcc').val() , 10);
    

提交回复
热议问题