gad*_*dss 5 html javascript iframe jquery
我有一个iframe,我想得到头部内容的价值.
<iframe>
<html>
<head>
<style>body{color:red;}</style>
<link type="text/css" rel="stylesheet" href="some link">
</head>
</html>
</iframe>
Run Code Online (Sandbox Code Playgroud)
我试过这个脚本:
var sett_wped_head = jQuery('iframe').contents().find("head").text();
alert(sett_wped_head);
Run Code Online (Sandbox Code Playgroud)
但它回来了body{color:red;}.我的目标是获得价值
<style>body{color:red;}</style>
<link type="text/css" rel="stylesheet" href="some link">
Run Code Online (Sandbox Code Playgroud)
可能吗?
你需要html()用来获取里面的html内容
var sett_wped_head = jQuery('iframe').contents().find("head").html();
// ------^------
alert(sett_wped_head);
Run Code Online (Sandbox Code Playgroud)