码迷,mamicode.com
首页 > 编程语言 > 详细

用javascript替换URL中的参数值

时间:2016-08-08 00:37:33      阅读:193      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!