javascript去掉url的一个参数

来源:互联网 发布:ga域名 编辑:程序博客网 时间:2024/05/17 09:05

点击一个复选框,选中的时候传递参数 ctype 不选中的时候去掉ctype参数

$(".ShowCompanyType").click(function(){


var check = $(this).attr("checked");
var ctype = check == true ? 1 : '';
var url = window.location.href;
var reg = new RegExp(/&ctype=(\d+)/i);
if(reg.test(url)){
url = url.replace(reg,"");
window.location.href = url;
} else {
window.location.href = url + "&ctype=" + ctype;
}

});

<input type="checkbox" class="ShowCompanyType"<?php if($ctype){?> checked="checked"<?php }?> />

0 0
原创粉丝点击