كيف يمكنني إعادة تنفيذ كود jQuery المنبثق الخارجي في النموذج الأولي؟
-
01-07-2019 - |
سؤال
لدي هذا الكود في 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");
لا تنتمي إلى StackOverflow