http://localhost/index.php?ctl=user&order=field&type=desc我需要将order=field中的field替换为传入的参数,type=desc中的desc替换为传入的参数
order=field和type=desc可能在?后的任何位置。

解决方案 »

  1.   

    http://hi.baidu.com/zhenyu5/blog/item/552dc51f5a35a2fc1ad5764c.html
    URL字符串可能是这样的 http://localhost/test.php?sort=time当然,如果只是一个参数提交的话,是很容易的,但是如果有很多参数的话,就需要做判定了,而事实上也不用那么复杂,做一个正则即可:        var url = window.location.href;
            url = url.replace(/[?|&|]sort(.*)&/ig,'&'); //替换在参数在中间的
            url = url.replace(/[?|&|]sort(.*)/ig,''); //替换参数在最后的        if(url.indexOf('?') != -1)
                url += '&';
            else
                url += '?';
            url += 'sort='+sort_value ; //sort_value 是要排序的值,将该参数放到最后边
            window.location.href = url ;