Jquery 和 prototype 比较

728x15 ad here

出自Guoshuang Wiki

跳转到: 导航, 搜索
$('p').addClass('updated')
.append('<span>This paragraph has just been updated!</span>')
.filter('p:hidden').show()
.appendTo('div#hidden-paragraphs'); 
  • Fill the 'bucket' with all p elements in the document
  • Add the class 'updated' to them
  • Append a span stating this at the end of the paragraphs
  • Filter the bucket for p elements that used to be hidden and show them
  • Move these previously hidden p elements in the DOM and append them to a div called 'hidden-paragraphs'.


Prototype:


var myAjax = new Ajax.Updater('elmentId', url, {method: 'get', parameters: params, onSuccess: myCallback});


jQuery:


$('#elementId').load(url, params, myCallback)



Prototype


$A(document.getElementsByTagName("table")).each(function(table){

 $A(table.getElementsByTagName("tr")).each(function(row,i){
   if ( i % 2 == 1 )
     Element.addClassName( row, "odd" );
 });

});


jQuery


$("tr:nth-child(odd)").addClass("odd");


个人工具
125x125 ad here
Advertisement
120x600 ad here