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

后端 未结 5 1903
耶瑟儿~
耶瑟儿~ 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:14

    There is a parseInt method for that or Number constructor.

    0 讨论(0)
  • 2021-01-12 01:18
    var count = parseInt(countUp, 10) + 1;
    

    See w3schools webpage for parseInt.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-12 01:36

    Use parseInt as in: var count = parseInt($("#"+countUp).val(), 10) + 1; or the + operator as in var count = +$("#"+countUp).val() + 1;

    0 讨论(0)
  • 2021-01-12 01:39
    parseInt(  $("#"+countUp).val()  ,  10  )
    
    0 讨论(0)
提交回复
热议问题