Skip to content

Instantly share code, notes, and snippets.

@topmask
Last active June 26, 2022 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topmask/7d41858acb347b45093543a99e356de0 to your computer and use it in GitHub Desktop.
Save topmask/7d41858acb347b45093543a99e356de0 to your computer and use it in GitHub Desktop.
以数字形式输入值
const numInput = document.getElementById('num-input');
let num;
// Bad: parseFloat() converts the string to a number
num = parseFloat(numInput.value);
// Good: returns a numeric value
num = numInput.valueAsNumber;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment