我基本上想做 replace(//g,"-")
和 replace(/'/g,"")
所以标题超过 60 岁60岁以上就变成蛞蝓了。这可以一次更换吗?
(toLowerCase()
将添加在上面之后)
最佳答案
您可以使用自定义函数作为第二个参数来实现:
var txt = "Over 60's";
txt = txt.replace(/ |'/g, function(match){
if (match === " "){
return "-";
}
return "";
});
txt // Over-60s
关于javascript - 字符串替换(w 替换为 x,y 替换为 z),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840073/