如何在Prototype中重新实现外部弹出式jQuery代码?
问题描述:
我在jQuery中有这个代码,我想用原型库重新实现。如何在Prototype中重新实现外部弹出式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()运算符等价的元素集合?
答
滤波可以使用像reject方法如此来完成:
$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");