2013-07-21 2 views
0

블로거 blogspot 캡션 테이블에서 텍스트를 복사하여 img alt에 추가하여 fancybox 슬라이드 쇼에 제목/캡션으로 표시하려고합니다.<tr>에서 텍스트 가져 오기 img to add alt <tr>

그래서,이 내가 가지고있는 HTML입니다 :

<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody> 
<tr>   <td style="text-align: center;"><a href="URL"><img align="right" alt="" src="URL" title="Ghostly Waves in the Valle de Rocas" width="320" /></a></td>   </tr> 
<tr>   <td class="tr-caption" style="text-align: center;">This is my Caption</td>   </tr> 
</tbody></table> 

그리고 내 스크립트입니다 :

$("tr-caption").each(function(){ 
    var Caption = $(this).text(); 

    if (Caption && Caption !== ''){ 
     $(this).parent(img).attr('alt', Caption); 
    } 
}); 

그리고 이것은 내가 위해 ....

<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody> 
<tr>   <td style="text-align: center;"><a href="URL"><img align="right" alt="This is my Caption" src="URL" title="Ghostly Waves in the Valle de Rocas" width="320" /></a></td>   </tr> 
<tr>   <td class="tr-caption" style="text-align: center;">This is my Caption</td>   </tr> 
</tbody></table> 
희망하려는 출력

하지만 작동하지 않습니다 ...

여기 ' 예 : http://jsfiddle.net/NCqW2/6/

어떤 도움을 주시면 감사하겠습니다! 볼 시간을 내 주셔서 감사합니다!

답변

1

을해야

$(this).parent().prev().find('img').attr('alt', Caption); 

$(this).parent(img).attr('alt', Caption); 

교체.

+0

네, 여기 피들 : http://jsfiddle.net/NCqW2/7/ –

+0

또는 http://techfoobar.com/jquery-next-in-dom/을 사용하고'$ (this) .prevInDOM ('img'). attr ('alt', caption);'- * 큰 고지 사항 : 나는 이것을 썼다. 그것이 정확하게 usecase에 꼭 맞기 때문에 여기에 게시하는 것. * – techfoobar

+1

그것은 꽤 빠르다! .... 매우 빨리 나는 그것을 바로 표시 할 수 없다! 정말 큰 도움을 주셔서 감사합니다, 그리고 의심의 여지가 산 시간을 구해줘! –

관련 문제