備註 html 效果圖 ...
備註
var url=window.location.href;//獲取地址欄 url var index=url.indexOf('#');//獲取#的位置 var paramVal=url.substr(index,url.length);//獲取 # 後面所有字元串
html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題</title> </head> <body> <script type="text/javascript" src="js/jquery-1.12.1.min.js"></script> <script type="text/javascript"> $(function(){ var a = 'https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Data_structures?userName=mona&pwd=3'; var b = a.split('/'); console.log(a); function parseParmStr(parmStr){ if(parmStr.indexOf("?")!=-1){ var index = parmStr.indexOf('?'); var parms = {}; parmStr = parmStr.substr(index+1); strs = parmStr.split('&'); //["userName=mona", "pwd=3"] for(var i=0;i<strs.length; i++){ parms[strs[i].split('=')[0]] = strs[i].split('=')[1]; } } return parms; } console.log(parseParmStr(a)); }) </script> </body> </html>
效果圖