1

code=hads1328fas&URLの文字列を削除したいので、

http://example.com/main/index.php?code=hads1328fas&store=food#home

http://example.com/main/index.php?store=food#home

ただし、文字列code=hads1328fas&は常に同じであるとは限らないため、この場合、以下のコードは機能しません。

var url = window.location.href;
url.replace('code=hads1328fas&')

その場合に可能な方法はありますか?

ありがとう

4

1 に答える 1

3

正規表現を使用します:

url = "http://example.com/main/index.php?code=hads1328fas&store=food#home";
url = url.replace(/code=[^&]+&/,'');

この後、urlには次が含まれます

http://example.com/main/index.php?store=food#home
于 2012-06-26T14:01:16.283 に答える