且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

查找并获取字符串中的数字

更新时间:2023-02-18 19:59:08

您只是用空字符串替换第一个非数字字符。请尝试使用:

You're replacing only the first non-digit character with empty string. Try using:

var id = window.location.href.replace(/\D+/g, '' ); alert(id);

(注意正则表达式末尾的全局标志)。

(Notice the "global" flag at the end of regex).