2008-09-17 25 views
1

Bu kodu jQuery'de prototip kitaplığı ile yeniden oluşturmak istediğime sahibim. jQuery burada listelenenPrototip'te harici açılır jQuery kodunu nasıl yeniden yapılandırabilirim?

// make external links open in popups 
// this will apply a window.open() behaviour to all anchor links 
// the not() functions filter iteratively filter out http://www.foo.com 
// and http://foo.com so they don't trigger off the pop-ups 

jQuery("a[href='http://']"). 
     not("a[href^='http://www.foo.com']"). 
     not("a[href^='http://foo.com']"). 
     addClass('external'); 

jQuery("a.external"). 
     not('a[rel="lightbox"]').click(function() { 
     window.open(jQuery(this).attr('href')); 
     return false; 
}); 

nasıl iteratif bir eşdeğerini kullanan elemanların bir koleksiyon filtre değil() operatörleri?

cevap

4
filtreleme reddetme yöntem şöyle kullanılarak yapılabilir

:

$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");