HTML input type=“number” still returning a string when accessed from javascript

后端 未结 7 1092
抹茶落季
抹茶落季 2020-11-29 08:18

I\'m new to javascript , I\'m trying learning how functions etc in JS and trying to add 2 numbers

7条回答
  •  伪装坚强ぢ
    2020-11-29 08:43

    1. HTML Input elements are documented to return string representing a number. See the documentation here : Documentation of HTML Input

    2. When you set input type="number" then these input field don't accept non numeric input but at the same time it doesn't make the input value type "number". The reason is inputted number contain digits as a subset of the valid characters, but they also contain completely non-numeric characters like spaces, hyphens and parenthesis.

提交回复
热议问题