JS截取URL中最后一个斜杠前(后)内容2021-09-16

JS获取URL中最后一个斜杠前面的内容

var url = window.location.href; 
var index = url.lastIndexOf("\/"); 
str = url.substring(0,index+1); 
console.log(str); // http://www.mywlaq.cn/archives/

JS获取URL中最后一个斜杠后面的内容

var url = window.location.href;
 var index = url.lastIndexOf("\/");
 str = url.substring(index + 1,url.length); console.log(str); // 3390.html

[https://blog.csdn.net/qq_35835160/article/details/89351713](https://blog.csdn.net/qq_35835160/article/details/89351713)

你可能感兴趣的:(JS截取URL中最后一个斜杠前(后)内容2021-09-16)