2015-11-23 29 views
5

Tôi có một số iframe và tôi muốn lấy giá trị nội dung đầu.jquery cách tải nội dung giá trị nội dung iframe

<iframe> 
<html> 
<head> 
<style>body{color:red;}</style> 
<link type="text/css" rel="stylesheet" href="some link"> 
</head> 
</html> 
</iframe> 

tôi đã cố gắng kịch bản này:

var sett_wped_head = jQuery('iframe').contents().find("head").text(); 
alert(sett_wped_head); 

nhưng nó sẽ trả về body{color:red;}. mục tiêu của tôi để có được giá trị là

<style>body{color:red;}</style> 
<link type="text/css" rel="stylesheet" href="some link"> 

là nó có thể?

Trả lời

5

Bạn cần phải sử dụng html() để nhận nội dung html bên

var sett_wped_head = jQuery('iframe').contents().find("head").html(); 
//              ------^------ 
alert(sett_wped_head); 
Các vấn đề liên quan