教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jquery 取url参数及在url后添加参数的例子

jquery 取url参数及在url后添加参数的例子

发布时间:2015-11-07   编辑:jiaochengji.com
本文介绍下,jquery获取url中参数,以及在url中添加参数的一个例子,有需要的朋友参考下吧。

jquery取得url参数与在url中添加参数的例子。
代码如下:

(function ($) { $.extend({ Request: function (m) { var sValue = location.search.match(new RegExp("[\?\&]" + m + "=([^\&]*)(\&?)", "i")); return sValue ? sValue[1] : sValue; }, UrlUpdateParams: function (url, name, value) { var r = url; if (r != null && r != 'undefined' && r != "") { value = encodeURIComponent(value); var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)"); var tmp = name + "=" + value; if (url.match(reg) != null) { r = url.replace(eval(reg), tmp); } else { if (url.match("[\?]")) { r = url + "&" + tmp; } else { r = url + "?" + tmp; } } } return r; } }); })(jQuery);

使用方法
www.jbxue.com/IOF.Signup/index_uscn_chs.html?act=1

1、取值使用
$.Request("act") = 1
2、url加参数
$.UrlUpdateParams(window.location.href, "mid", 11111),
输出结果:
window.location.href?mid=11111

您可能感兴趣的文章:
jquery 取url参数及在url后添加参数的例子
jquery获取url及url参数的方法
jquery 当前页面url传递的参数的例子
url链接中特殊字符转义方法
jquery获得url参数列表的例子
javascript 获取url参数的小例子
jquery 获取URL请求参数的小例子
Js 取得当前页面的URL网址参数
jQuery 获取URL参数的插件
Jquery Ajax的Get方式时需要注意URL地方

[关闭]
~ ~