Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
请耐心等待,因为我对 javascript 很陌生。
我正在制作一个简单的进度条脚本。我让用户将进度百分比输入变量之一。
与其给出错误并让用户重新输入他们的数字,我能做些什么来让javascript忽略任何不是数字的字符。
您可以使用正则表达式删除所有非数字符号:
user_input = user_input.replace(/[^0-9]/g, "");
例子:
> "a347adsf73".replace(/[^0-9]/g, ""); "34773"