jquery
  • flickr
  • 2012-04-10 3 views 0 likes 
    0

    현재 graphic overlay application (Flickr 콘텐츠 표시)을 개발 중입니다.텍스트 감지로 이미지 소스 변경

    탈퇴 한 사용자의 이미지를 대체하고 싶습니다.

    내 HTML 구조는 다음과 같다 :

    <ul> 
        <li> 
        <div class="imgbk"> 
         <img src='http://farm6.static.flickr.com/5312/7057785005_2966a34f1f.jpg'/> 
         <a href='http://www.flickr.com/photos/[email protected]/7057785005'>Link</a> 
        </div> 
        </li> 
    </ul> 
    

    문자열은 href가에 위치한 [email protected]이다이 예에서 테스트 할 수 있습니다.

    href를 구조는 항상 동일합니다 : flickr.com/사진/사용자 ID/ImageID

    지금까지이 서버 쪽 일을했지만, 내 웹 사이트에 엄청난 트래픽이 클라이언트 측을 할 저를 강요했다. 내 jQuery 지식이 제한되어 있으므로 도움을 요청하고 있습니다!

    답변

    0

    감사들, 여기에 귀하의 응답에 따라 나의 새로운 코드 : 여기

    var OptOutArray = ["[email protected]", "[email protected]"]; 
    
    $('img').each(function() { 
        var matches = $(this).next().attr("href").split('/')[4]; 
        if ($.inArray(matches, OptOutArray) > -1) { 
        $(this).attr("src", "http://core.flickeflu.com/doh.gif"); 
        } 
    });​ 
    

    예 : http://jsfiddle.net/jgYs8/

    0

    찾고 계신 것이 확실하지 않습니다. 당신이 그 문자열을 잡아하려는 경우, 당신은 할 수있는 다음

    var a = $('.imgbk a').attr('href'); 
    var b = a.split('/'); 
    alert(b[4]); 
    

    예 : 기본적으로 http://jsfiddle.net/jasongennaro/AQw9X/

    , href 속성을 찾은 다음 배열의 각 조각을 배치의 /에 그것을 분할 b. 배열의 어느 항목을 선택할 수 있는지 알 수 있도록 결과에 경고했지만, 원하는 항목을 선택할 수 있습니다.

    0

    찾고있는 것이 페이지의 모든 이미지에서 해당 코드가 포함 된 항목을 확인하는 방법 인 경우 다음과 같이 할 수 있습니다. 당신이에 대해 확인하는 코드의 전체 목록을 가지고 있다면

    var optOutstr = "[email protected]"; 
    
    $(img).each(function() { 
        if (this.href.match(new RegExp("/" + optOutStr + "/")) { 
         this.href = "whatever you want to replace the URL with"; 
         $(this).prev().attr("src", "whatever you want to replace the image with"); 
        } 
    }); 
    

    는 코드의 전체 무리에 대해 그것을 확인하는 더 효율적인 방법이 될 것입니다.

    var optOutMap = {"[email protected]": true, ....}; 
    
    $(img).each(function() { 
        var matches = this.href.match(/flickr.com\/photos\/([^\/]+)\//); 
        if (matches && matches[1] in optOutMap) { 
         this.href = "whatever you want to replace the URL with"; 
         $(this).prev().attr("src", "whatever you want to replace the image with"); 
        } 
    }); 
    
    관련 문제