Ok so I have about six of these calendars on page, so thats around 180 td items (1 for each date):
each td has an id that is equal to that day's timestamp.
the dates I开发者_运维百科 want are the red ones (class of .booked
).
So i need the fastest way to 'serialize' the ids for td.booked
items, any ideas?
You can get an array of the IDs using .map()
, like this:
var ids = $("td.booked").map(function() { return this.id; }).get();
This would result in an array like this:
["id1", "id2", "id3", ... ]
What exactly do you mean by "serialize"?
If they are being marked on the client, then the fastest way to collect references to them would be to collect them as they are marked. Then, you already an index to them when you need it, and no retroactive query is needed.
How about this:
var str = '';
$(function(){
$('td.booked').each(function(index){
str += '&td' + index + "=" + encodeURIComponent($(this).text());
});
});
alert(str);
精彩评论