jquery取得url的参数
url:http://localhost:1142/YiYiWorkRoom/UI/Admin/ShowCases.aspx&title=hello
目的:取得参数:hello
取得url参数的函数
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; //返回参数值
}
传递一个参数,跳转到另一个页面:
window.location.href("CaseMng.aspx?title=" + escape($(":checked").val()));
用法:
var title = unescape(getUrlParam("title"));
alert(title);