<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>
原文:http://www.cnblogs.com/doseoer/p/5747715.html