js - 正斜杆网址转换
2018-8-7(更新)
1 let http = 'http://www.baidu.com/com/img/1.jpg'; 2 let https = 'http:\\www.baidu.com\\com\\img\\1.jpg'; 3 4 // 转换为反斜杆 5 function backSlash(url) { 6 return url = url.replace(/\/\//g, "\\\\").replace(/\//g, "\\"); 7 } 8 9 // 转换为正斜杆 - 待优化 10 function positiveSlanting(url) { 11 return url = url.replace(/\\\\?/, "\/\/").replace(/\\/g, '/'); 12 } 13 14 15 console.log(backSlash(http), positiveSlanting(https));