js 獲取地址第1個斜杠后的內容或地址前一部分


var value = "https://www.baidu.com/20210922/95b22ab5034b2d0f.jpg";
const str = value.split("https://"); //https://進行分割,
const index = str[1].indexOf("/")+1; //indexOf 獲取第一個斜杠的索引,
console.log(str[1].substring(index)); //substring 截取,

 

//獲取前面的域名

var i = "https://www.baidu.com/20210922/95b22ab5034b2d0f.jpg";
console.log(i.match(/^(?:[^\/]|\/\/)*/));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2024 CODEPRJ.COM