gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:56:59 24 4
gpt4 key购买 nike

我在 jQuery 中有这段代码,我想用原型(prototype)库重新实现。

// 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");

关于javascript - 如何在 Prototype 中重新实现外部弹出式 jQuery 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/85887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com