我的网址如下所示:
http://www.something.hu/#/ask?kerdesPost=fdasdas%20ad%20asd%20ad%20asdas
我想得到 onlyfdasdas%20ad%20asd%20ad%20asdas
或 only kerdesPost=fdasdas%20ad%20asd%20ad%20asdas
。
我怎样才能通过 JavaScript 做到这一点?最短的方法是什么?
我的网址如下所示:
http://www.something.hu/#/ask?kerdesPost=fdasdas%20ad%20asd%20ad%20asdas
我想得到 onlyfdasdas%20ad%20asd%20ad%20asdas
或 only kerdesPost=fdasdas%20ad%20asd%20ad%20asdas
。
我怎样才能通过 JavaScript 做到这一点?最短的方法是什么?
您可以尝试以下方法:
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)
}
这应该可以满足您的需求。