كيف يمكنني إعادة تنفيذ كود jQuery المنبثق الخارجي في النموذج الأولي؟

StackOverflow https://stackoverflow.com/questions/85887

سؤال

لدي هذا الكود في jQuery، وأريد إعادة تنفيذه باستخدام مكتبة النموذج الأولي.

// 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;
});

كيف يمكنك تصفية مجموعة من العناصر بشكل متكرر باستخدام ما يعادل عوامل التشغيل not() المدرجة هنا في jQuery؟

هل كانت مفيدة؟

المحلول

يمكن إجراء التصفية باستخدام طريقة الرفض كما يلي:

$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top