jQuery has a plugin call开发者_JAVA百科ed jExpand for expanding table rows. Does Prototype have an equivalent?
The source of jExpand is so small I just went ahead and translated it for you.
Element.addMethods(
'TABLE',
{
addJExpand : function(elem){
elem = $(elem);
elem.select('tr:nth-child(even)').each(function(child){child.addClassName('odd')});
elem.select('tr:nth-child(odd)').each(Element.hide);
elem.down('tr').show();
elem.select('tr:nth-child(even)').each(
function(child){
child.observe('click',
function(){
child.next().toggle();
}
);
}
);
}
}
);
Just call it using table.addJExpand()
, where table
is your prototype-extended variable. You can also use Element.addJExpand
for times when you're using .each
.
You're welcome.
精彩评论