转:JS-正斜杠和反斜杠的转换

阅读更多

转载链接:https://www.cnblogs.com/zqn518/p/6707415.html

 

将正斜杠转换成反斜杠

var url = "http://localhost:64177/Home/AccordionIndex";


url = url .replace("\/\/", "\\\\");
url = url .replace("\/", "\\");
url = url .replace("\/", "\\");
alert(url);


将会弹出:http:\\localhost:64177\Home\AccordionIndex

 
将反斜杠转换成正斜杠:
var strurl = "http:\\localhost:64177\Home\AccordionIndex";

strurl = strurl .replace("\\\\", "\/\/");
strurl = strurl .replace("\\", "\/");
strurl = strurl .replace("\\", "\/");
alert(strurl );

将会弹出:http://localhost:64177/Home/AccordionIndex

你可能感兴趣的:(正斜杠与发斜杠的转换,/转换成\,\转换成/)