<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中的下划线替换空格?
- 如何使用正则表达式用Javascript替换字符串中特定单词以外的所有内容
- 用Javascript中的新HTML字符串替换字符串中的所有单词
- 用php替换字符串中的特定URL
- 用JavaScript字符串中的单个空格替换多个空格
- 用短划线替换URL中的点
- Javascript Regex替换url中的子目录
- 用正则表达式拆分和替换javascript中的unicode单词
- javascript中字符串连接时用Array.join()替换 string += "xx",换来几十倍的速度提升
- javascript中字符串连接时用Array.join()替换 string += "xx",换来几十倍的速度提升