我的网址是在两种语言之间切换内容
http://mydomanin.org/km/components#children-with-disablities
或
http://mydomanin.org/en/components#children-with-disablities
var current_url = document.URL;
var match_url = current_url.replace(/\/km/g,'/en');
console.log(match_url);
我想如果找到\km
将被\en
替换,如果找到\en
替换为\km
我该怎么做?
答案 0 :(得分:3)
试试这个:
var replace = { km:"en", en:"km" };
str = str.replace(/km|en/gi, function(match){
return replace[match];
});
<强> Demo 强>