jquery获取URL参数
2014-04-27 11:37
323 查看
本文转自:http://blog.csdn.net/salc3k/article/details/7286296
代码示例:
1.html:
file:///C:/Users/zhanglei/Desktop/1.html?picid=8
8
8
代码示例:
1.html:
<!DOCTYPE html> <html> <head> <title></title> <style type='text/css'> </style> </head> <body> </body> <script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script> <script type='text/javascript' src='jqueryPlugin.js'></script> <script type='text/javascript'> $(document).ready(function(){ // 访问该页面时,在url末尾添加?picid=8 console.log(window.location.href); console.log($.getUrlParam('picid')); console.log(getUrlParam('picid')); }); function getUrlParam(name){ //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //返回参数值 if (r!=null) return unescape(r[2]); return null; } </script> </html>jqueryPlugin.js:
(function($){ $.getUrlParam = function(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r!=null) return unescape(r[2]); return null; } })(jQuery);运行结果:
file:///C:/Users/zhanglei/Desktop/1.html?picid=8
8
8
相关文章推荐
- 【jquery前端开发】可调整的幻灯片(图片轮播)
- jQuery常用遍历节点方法
- jquery实现复选框联动
- Dom对象和jQuery对象的相互转化
- Jquery实现仿淘宝天猫左侧分类导航插件
- jQuery基础与一些细节(2)
- 利用jQuery和CSS实现环形进度条
- window.onload 、body.onload 以及 jQuery 等dom加载完成后执行脚本的区别
- struts2+jQuery+ajax调用演示
- [jQuery1.9]Cannot read property ‘msie’ of undefined错误的解决方法
- SpringMVC:整合JQUERY与JSON
- 用el表达式显示jquery请求servlet数据的中文乱码问题
- 左右的移动<<>><>jQuery的实现
- [原]左右的移动<<>><>jQuery的实现
- jquery mobile如何实现滑动屏幕跳转页面
- jQuery基础与一些细节(1)
- jQuery学习之prop和attr的区别
- 使用 JQueryMobile 点击超链接提示“error loading page” 错误
- jquery简单制作悬浮导航 滚动到哪儿 定位到哪儿
- jquery cookie 本地不能工作的原因