JS-斜槓和反斜槓的轉換

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

將斜槓轉換成反斜槓:spa

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

alert(url);di

將會彈出:http:\\localhost:64177\Home\AccordionIndexco

 

將反斜槓轉換成斜槓:localhost

var strurl = "http:\\localhost:64177\Home\AccordionIndex";

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

將會彈出:http://localhost:64177/Home/AccordionIndex

相關文章
相關標籤/搜索