js, how to get one part in location.hash
I want to get the location.hash
part, the word after first %20
. But how?
For explain
http://localhost/text/search.php?search=sweet%20girl => girl
http://localho开发者_Go百科st/text/search.php?search=fashion => NULL
http://localhost/text/search.php?search=2011%20best%20and%20worst => best and worst
var s = decodeURIComponent(location.search);
var index = s.indexOf(" ");
s = index === -1 ? s.substr(index + 1) : null;
Use the unescape function first. After that you can do a regexp replace.
var url = "http://localhost/text/search.php?search=2011%20best%20and%20worst";
alert (unescape(url).replace(/^\S* /,""));
精彩评论