How can I change an HTML input value's data type to integer?

后端 未结 5 1905
耶瑟儿~
耶瑟儿~ 2021-01-12 00:39

I\'m using jQuery to retrieve a value submitted by an input button. The value is supposed to be an integer. I want to increment it by one and display it.

//          


        
5条回答
  •  别那么骄傲
    2021-01-12 01:30

    To convert strValue into an integer, either use:

    parseInt(strValue, 10);
    

    or the unary + operator.

    +strValue
    

    Note the radix parameter to parseInt because a leading 0 would cause parseInt to assume that the input was in octal, and an input of 010 would give the value of 8 instead of 10

提交回复
热议问题