<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>