如何在Prototype中重新实现外部弹出式jQuery代码?
时间:2020-03-05 18:59:32 来源:igfitidea点击:
我在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; });
如何使用与jQuery此处列出的not()运算符等效的元素来迭代地过滤元素集合?
解决方案
回答
可以使用拒绝方法进行过滤,如下所示:
$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");