1. 程式人生 > >js獲取路由(http://www.aaa.com/module/218.html)中的id

js獲取路由(http://www.aaa.com/module/218.html)中的id

//返回當前頁面的 URL(http://www.aaa.com/模組名/216.html)
var strUrl = window.location.href;
//把一個字串按照/分割成字串陣列 array['http:','www.aaa.com','模組名','216.html']
var arrUrl = strUrl.split("/");
//獲取216.html
var strPage = arrUrl[arrUrl.length-1];
//獲取數值(26)
var id=strPage.replace(/[^0-9]/ig,"");