首页 > 编程语言 > 详细

用javascript替换URL中的参数值

时间:2016-08-08 00:34:18      阅读:235      评论:0      收藏:0      [点我收藏+]
<script>
function changeUrlArg(url, arg, val){ 
	var pattern = arg+‘=([^&]*)‘; 
	var replaceText = arg+‘=‘+val;
	return url.match(pattern) ? url.replace(eval(‘/(‘+ arg+‘=)([^&]*)/gi‘), replaceText) : (url.match(‘[\?]‘) ? url+‘&‘+replaceText : url+‘?‘+replaceText);
} 

document.write(changeUrlArg(‘http://www.t.com/test.php?class_id=3&id=2‘, ‘id‘, 4));
</script>

 

用javascript替换URL中的参数值

原文:http://www.cnblogs.com/doseoer/p/5747715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!