如何从href链接中删除特定字符?

时间:2016-09-12 10:10:03

标签: javascript string

我的链接是https://mytestsite.com/search/label/interesting?m=1

如何从链接末尾删除?m=1

3 个答案:

答案 0 :(得分:1)

你可以这样做



var address = "https://mytestsite.com/search/label/interesting?m=1";
var pieces = address.split('?')[0];

// to show address after being sliced
alert(pieces);




答案 1 :(得分:0)

您只需将网址拆分为?字符。

var link = 'https://mytestsite.com/search/label/interesting?m=1';
var arr = link.split('?');
console.log(arr[0]);

arr[0]中,您将获得结果 - https://mytestsite.com/search/label/interesting

答案 2 :(得分:-1)

    var str = "https://mytestsite.com/search/label/interesting?m=1";
    str = str.slice(0, -4);