0

我的网址如下所示: http://www.something.hu/#/ask?kerdesPost=fdasdas%20ad%20asd%20ad%20asdas

我想得到 onlyfdasdas%20ad%20asd%20ad%20asdas或 only kerdesPost=fdasdas%20ad%20asd%20ad%20asdas

我怎样才能通过 JavaScript 做到这一点?最短的方法是什么?

4

1 回答 1

7

您可以尝试以下方法:

if((window.location.href).indexOf('?') != -1) {
    var queryString = (window.location.href).substr((window.location.href).indexOf('?') + 1); 

    // "queryString" will now contain kerdesPost=fdasdas%20ad%20asd%20ad%20asdas

    var value = (queryString.split('='))[1];

    // "value" will now contain fdasdas%20ad%20asd%20ad%20asdas

    value = decodeURIComponent(value);

    // "value" will now contain fdasdas ad asd ad asdas (unescaped value)
}

JSFiddle

这应该可以满足您的需求。

于 2013-05-17T12:21:15.740 回答