admin管理员组文章数量:1295236
How can i get multiple values in a jquery hash?
Example:
:value&v:id1212 same as but without page refresh /?l=value&v=id1212
I thought something like:
var hash = location.hash.replace(/^.*?#/, '');
var lVal = (/^l:/.test( hash ));
var vVal = (/^v:/.test( hash ));
but how can i fix that var lVal only reads untill the & sign? Am i on the right direction?
How can i get multiple values in a jquery hash?
Example:
http://mysite./#l:value&v:id1212 same as but without page refresh http://mysite./?l=value&v=id1212
I thought something like:
var hash = location.hash.replace(/^.*?#/, '');
var lVal = (/^l:/.test( hash ));
var vVal = (/^v:/.test( hash ));
but how can i fix that var lVal only reads untill the & sign? Am i on the right direction?
Share Improve this question edited Jul 8, 2012 at 17:26 rodneyrehm 13.6k1 gold badge42 silver badges56 bronze badges asked Jul 8, 2012 at 17:11 KipKip 5134 silver badges14 bronze badges2 Answers
Reset to default 7Try to split your string by &
sign and then retrieve values:
var hash = location.hash.replace(/^.*?#/, '');
var pairs = hash.split('&');
var lVal = pairs[0].split(':')[1];
var vVal = pairs[1].split(':')[1];
I believe you might be looking for something like History.js to help you ease the pain. Also URI.js has a fragment-abuse plugin for data fragments. Otherwise try something like
var data = {};
var tokens = location.hash.substring(1).split('&');
for (var i=0, l=tokens.length; i < l; i++) {
var token = tokens[i].split(':');
// maybe token[1] is escaped or something?!
data[token[0]] = token[1];
}
console.log(data);
本文标签: javascriptHow to get multiple values from jquery hashStack Overflow
版权声明:本文标题:javascript - How to get multiple values from jquery hash - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741616711a2388566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论