var s ="总金额4500元";
var num= s.replace(/[^0-9]/ig,"");
alert(num);//4500
上述示例会把数字匹配到直接转成数字;
var s ="总金额4500元,利润:28";
var num = s.replace(/[^0-9]/ig,"");
alert(num);//450028
如果遇到字符夹带数字的情况:上述就会直接转成数字拼接起来的方式;
标签:数字,Js,var,num,4500,字符串,replace,ig
来源: https://www.cnblogs.com/BraveBoy/p/10943173.html