Input value is a string instead of a number

前端 未结 4 1694
日久生厌
日久生厌 2020-11-29 13:08

When i add a number to the input it doesn\'t change the value that stays at 5 and when i go in the console and type uw.value i get \"6\" back instead of 6 which i typed in

4条回答
  •  眼角桃花
    2020-11-29 13:48

    var uw = parseInt(document.getElementById("wakken").value, 10); // (value, radix)
    if (typeof uw === "number") console.log("works! 'uw' is an int");
    

    Will log "works! 'uw' is an int", because we collected the value and used parseInt(_: String) to convert it to an int.

提交回复
热议问题