如何在Prototype中重新实现外部弹出式jQuery代码?

时间:2008-09-17 17:58:15

标签: javascript jquery popup prototypejs

我在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()运算符等价的方法迭代过滤元素集合?

1 个答案:

答案 0 :(得分:4)

可以使用拒绝方法完成过滤,如下所示:

$$('a').reject(function(element) { return element.getAttribute("href").match(/http:\/\/(www.|)foo.com/); }).invoke("addClassName", "external");