对于网站开发中,经常需要取得URL中的参数值。
来源:互联网 发布:碎屏 mac 壁纸高清 编辑:程序博客网 时间:2024/06/10 17:40
对于网站开发中,经常需要取得URL中的参数值。
方法1、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];
}
//取得传过来的name参数
name=URLParams["name"];
document.write(name);
参考资料:http://hi.baidu.com/lost2happy/blog/item/0fd6df91357c7287a877a407.html
方法2、jquery本身也不存在取得URL参数的方法,但是已经存在插件,可以直接取得URL等参数
插件连接主页: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插件本身代码
- 对于网站开发中,经常需要取得URL中的参数值。
- magento------取得URL参数
- java中取得Oracle存储过程输出参数中的值
- iOS开发初学者需要经常去的论坛或网站
- URL中参数中的加号
- javascript js 取得网页的url中带的参数 js 获取 url 参数
- 取得url地址写入参数
- JS取得URL所有参数
- jquery取得url的参数
- js中substring或split方法取得URL中的域名
- js中自定义QueryString方法,获取url中的参数值
- Form表单需要使用Post传递url中的参数
- 取得文章中的URL地址~
- 对于jQuery formValidator ver3.3 中ajaxValidator中的url无法传递动态值的处理方式
- 获取url中的参数值
- 在网站开发中经常用到的javaScript技术[1]
- 网站开发中经常用到的javaScript技术
- 在网站开发中经常用到的javaScript技术
- Solving the absence of Android source...
- RSSI
- linux命令:du
- 转自Stackoverflow:Parallelization: pthreads or OpenMP?
- synchronizing using completion function
- 对于网站开发中,经常需要取得URL中的参数值。
- abap 在table control(表控件) 实现查找功能
- iPhone 隐藏Status Bar和修改程序名称的小技巧
- linux 应用程序调试初步
- OpenGL怎么用
- 如何判断Javascript对象是否存在
- tomcat + ssl
- IE的onunload事件里调用DWR
- Tomcat5.5项目部署方式及相应的数据源配置