jquery获取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; //返回参数值

}



例子

$(function(){
var type=getUrlParam("type");
if(type==1){
   $('#showSlot').html('直播');
}
if(type==2){
$('#showSlot').html('录播');
}
});

猜你喜欢

转载自blog.csdn.net/lunsunhuan1825/article/details/73321267