开发者

Having trouble with javascript Replace()

开发者 https://www.devze.com 2023-04-09 00:36 出处:网络
This code will replace the comma\'s no problem, but will leave the $ for some reason... Is it set开发者_JAVA技巧 up wrong? Trying to replace the $ also.

This code will replace the comma's no problem, but will leave the $ for some reason... Is it set开发者_JAVA技巧 up wrong? Trying to replace the $ also.

function doValidate() { 
    var valid = true;  
    document.likeItemSearchForm.sup.value = document.likeItemSearchForm.sup.value.replace(/\$|,/g, "")  
    return valid;   
}


Try this:

'asd$asd,asd,asd$,asd'.replace(/[\$,]/g,'');

JSFIDDLE -edit- fixed link


try this:

"$12,121.30".replace(/[\$,]/g, "");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号