jquery: i have to use parseInt() even when deal with numbers, why?

前端 未结 4 416
后悔当初
后悔当初 2021-01-21 08:24

i have the following script


                        
    
提交评论

  • 2021-01-21 08:27

    Form field values are always stored as strings. Whether or not they look like integers is irrelevant; they're strings. You need to convert them to integers before treating them as such :)

    0 讨论(0)
  • 2021-01-21 08:42

    Values are never integers as such, the fact that you put numbers there instead of who-knows-what is your choice only.

    0 讨论(0)
  • 2021-01-21 08:42

    jQuery's val() function always returns a string. In many cases you can mix numbers and strings (in arithmic for example), when comparing two string variables, javascript will perform a string comparison, not a numeric comparison (which is to be expected)

    0 讨论(0)
  • 提交回复
    热议问题