Javascript 字符串替换(w为x,y为z)
我基本上想做Javascript 字符串替换(w为x,y为z),javascript,Javascript,我基本上想做replace(//g,“-”)和replace(//'/g,”)这样一个60岁以上的标题就变成了60岁以上的鼻涕虫。一次更换可以吗 (toLowerCase()将在上述内容之后添加)您可以使用自定义函数作为第二个参数: var txt = "Over 60's"; txt = txt.replace(/ |'/g, function(match){ if (match === " "){ return "-"; } return ""; })
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
参见标题
和slug
从何而来?我的错误,误读了选项,删除了评论,以免混淆其他人