在Javascript中替换字符串中的多个字符实例

Viv*_*vek 2 javascript string

所以我有这段代码:

var thisValue = $("input[id*=ID222]").val(); 
thisValue = thisValue.replace(',','');
Run Code Online (Sandbox Code Playgroud)

基本上我想删除此输入元素中的所有逗号,以便进行进一步处理.上面的代码在字段中只有一个逗号时有效,但不适用于多个逗号.还有另外一种方法吗?我尝试了replaceAll,但它没有用.

lon*_*day 7

您必须使用正则表达式进行全局替换.您不能通过将字符串传递给replace:

thisValue = thisValue.replace(/,/g,'');
Run Code Online (Sandbox Code Playgroud)