Js+Jq获取URL参数的集中方法
2014-05-20 11:40
686 查看
插件连接主页:https://github.com/allmarkedup/jQuery-URL-Parser
下载链接:http://download.github.com/allmarkedup-jQuery-URL-Parser-bb2bf37.zip
Examples of use
Using the current page's url (for these examples https://mysite.com/information/about/index.html?itemID=2&user=dave):
// get the protocol
jQuery.url.attr("protocol") // returns 'http'
// get the path
jQuery.url.attr("path") // returns '/information/about/index.html'
// get the host
jQuery.url.attr("host") // returns 'mysite.com'
// get the value for the itemID query parameter
jQuery.url.param("itemID") // returns 2
// get the second segment from the url path
jQuery.url.segment(2) // returns 'about'
Using a different url to the current page:
// set a different URL and return the anchor string
jQuery.url.setUrl("http://allmarkedup.com/category/javascript/#footer").attr("anchor") // returns 'footer'
JS原生获取:最原始的JS方法:
var URLParams = new Array(); var aParams = document.location.search.substr(1).split('&'); for (i=0; i < aParams.length ; i++){ var aParam = aParams[i].split('='); URLParams[aParam[0]] = aParam[1]; }
这样调用:http://127.0.0.1/index.php?name=name1&cid=123
//取得传过来的name参数
name=URLParams["name"];
document.write(name);
//取得传过来的cidcid=URLParams["cid"];正则分析法:方法一:
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }这样调用:
alert(GetQueryString("参数名1")); alert(GetQueryString("参数名2")); alert(GetQueryString("参数名3"));方法二:
![](http://common.cnblogs.com/images/copycode.gif)
<Script language="javascript"> var Request = new Object(); Request = GetRequest(); var 参数1,参数2,参数3,参数N; 参数1 = Request['参数1']; 参数2 = Request['参数2']; 参数3 = Request['参数3']; 参数N = Request['参数N']; </Script>
相关文章推荐
- Js+Jq获取URL参数的集中方法示例代码
- Js+Jq获取URL参数的集中方法示例代码
- js 获取url参数方法
- 一个JS获取url参数的方法
- js获取url参数的简易方法
- js&jquery获取url域名及参数的方法
- js获取url参数的几种方法
- js 获取Get方法URL传来的参数值 及设置url参数
- js获取URL的参数的方法(getQueryString)
- 转:获取网页URL地址及参数等的两种方法(js和C#)
- JS 获取 url 参数的几种方法
- js获取URL参数的方法
- JS获取Url参数的通用方法
- js获取url参数便易方法
- 引用 js中常用方法-去除字符串空格,各类型验证,获取url参数等
- js获取url参数方法
- 获取网页URL地址及参数等的两种方法(js和C#)
- js获取网页的url文件名( 例如index.aspx),js获取url的参数(例如获取 ?cid=joeylee的值),给jquery拓展方法
- js获取url中含中文的参数方法
- js获取URL的参数的方法(getQueryString)示例