如何在 Prototype 中重新实现外部弹出 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;
});
如何使用 jQuery 中列出的 not() 运算符的等效项来迭代过滤元素集合?
解决方案
可以使用拒绝方法来完成过滤,如下所示:
$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");
不隶属于 StackOverflow