2014-01-23 77 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

是来自同一个域显示页面的iframe? – 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

用途:

var link = $('#bcd a').attr('href'); 
text=$('#bcd a').text(); 
alert(link+"----"+text); 
相关问题