小智 24
您必须解析iframe内容.
$("#frameid").contents().find("div").html('My html');
Run Code Online (Sandbox Code Playgroud)
更多信息:http://api.jquery.com/contents/
Tow*_*own 21
你可以contents()用来操纵的内容iframe.
$("#frameDemo").contents().find("div").html("new HTML content goes here");
Run Code Online (Sandbox Code Playgroud)
以下是jQuery文档中的示例:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<iframe src="http://api.jquery.com/" width="80%" height="600" id='frameDemo'></iframe>
<script>$("#frameDemo").contents().find("a").css("background-color","#BADA55");</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果要更改<body>iframe标记内的内容,可以使用以下代码:
$("#iframe_id").contents().find("body").html('my_new_content');
Run Code Online (Sandbox Code Playgroud)