Luke Lutman schrieb: > I was thinking of something a little fancier ;-) > > jQuery.query = function() { > var r = {}; > var q = location.search; > q = q.replace(/^\?/,''); // remove the leading ? > q = q.replace(/\&$/,''); // remove the trailing & > jQuery.each(q.split('&'), function(){ > var key = this.split('=')[0]; > var val = this.split('=')[1]; > // convert floats > if(/^[0-9.]+$/.test(val)) > val = parseFloat(val); > // ingnore empty values > if(val) > r[key] = val; > }); > return r; > }; > > Then you could use it like so: > > http://www.bork.com?foo=helloworld&bar=0.333& > > $.query()['foo']; // helloworld (string) > $.query()['bar']; // 0.333 (number) > In that case, you should just assign the result to jQuery.query, eg: (function() {
jQuery.query = r = {}; var q = location.search; q = q.replace(/^\?/,''); // remove the leading ? q = q.replace(/\&$/,''); // remove the trailing & jQuery.each(q.split('&'), function(){ var key = this.split('=')[0]; var val = this.split('=')[1]; // convert floats if(/^[0-9.]+$/.test(val)) val = parseFloat(val); // ingnore empty values if(val) r[key] = val; }); })(); Considering that location.search does not change. I hope I'm not confusing something. -- Jörn _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/