Luke Lutman schrieb:
> The attr() method returns a string, rather than the jQuery object, so you
> won't be able to chain
> it. You could modifiy the $.query function and pass in the value of q ...
> like so:
>
> jQuery.query = function(q) {
> var r = {};
> 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 call it like this:
>
> q = $.query($(this).attr('href'));
>
> Luke
That won't work for two reasons: $(this).attr('href') most likely
returns a complete url, thus there is no leading "?".
Secondly if you have a parameter like "number=0", it won't be put into
the hash because after parseFloat val == 0 which evaluates to false.
See here for a demo with these things fixed:
http://stilbuero.de/demo/query.html?foo=bar
-- Klaus
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/