开发者

jQuery and generating links

开发者 https://www.devze.com 2023-02-16 02:30 出处:网络
How can I get jQuery to generate the link for a get such that I don\'t have to try to hand code all the query parameter开发者_JS百科s?

How can I get jQuery to generate the link for a get such that I don't have to try to hand code all the query parameter开发者_JS百科s?

Alternative to doing this:

$('a.csvBtn').attr('href',"CSVReporter?cam=" + id + "&range);

As we know jquery.get({url:n, data:xxx}); and jQuery takes the data and builds a link to the url http://blah.com/n?x=1&x=2.


You can use jQuery.param to convert an object into a query string.

var qs = {};
qs.cam = id; 
qs.range = 'blah';
var query_string  = jQuery.param(qs); //for id=foo, this will be cam=foo&range=blah

Or, in use:

$('a.csvBtn').attr('href', function(){
     var qs = {cam : id, range : 'blah'};
     return "CSVReporter?"+jQuery.param(qs); 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号