2014-01-23 2 views
0

코드 구조는 iframe과 같습니다.jquery를 사용하여 하이퍼 링크 값 및 텍스트 필드를 얻는 방법

<div id="abc"> 
<div id="bcd"><a href="i want this hyperlink" title="sdf"><img src="" alt="i want this text"</a> 
<div><h1><a href="i want this hyperlink">i want this text</a></div> 
</div> 
</div> 

이 같은 시도했지만이

var $links= $("#frametest").contents().find("#abc").contents().find("#bcd").contents().find('a'); 
var link= $links.attr['href']; 
alert(link); 
+0

인가? – adeneo

답변

0

이 시도 작동하지 않습니다 :

찾을 텍스트 :

$('#bcd').find('a').each(function(index){ 
    $(this).text(); 
}); 

href가 찾을 수 :

$('#bcd').find('a').each(function(index){ 
    $(this).attr('href'); 
}); 
함께

:

$('#bcd').find('a').each(function(index){ 
     alert($(this).attr('href') + ' ' + $(this).text()); 
    }); 
0

단지로 시도 :

$('#bcd a').each(function(){ 
    var link = $(this).attr('href'); 
    var text = $(this).text(); 
    alert(text + ': ' + link); 
}); 
0

사용 : 동일한 도메인에서 페이지를 표시하는 iframe이이

var link = $('#bcd a').attr('href'); 
text=$('#bcd a').text(); 
alert(link+"----"+text); 
관련 문제