문제

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");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top