Js把URL中的参数解析为一个对象
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>Js把URL中的参数解析为一个对象</title> <body> <script type="text/javascript"> // 把URL的参数解析为对象 function parseUri(uri){ var para = uri.split('?')[1], arr_para = para.split('&'), i = 0, n = arr_para.length; for(; i<n; i++){var arr = arr_para[i].split('='); this[arr[0]] = arr[1];} } // 测试 var url = "http://search.360buy.com/Search?keyword=HTCone&enc=utf-8&area=1"; var obUrl = new parseUri(url); console.log(obUrl.keyword); </script> </body> </html>