<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<iframe src="demo.html" id="myFrame" name="myFrame" frameborder="0"></iframe>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(function(){
console.log($('#myFrame').contents().find('#btn').text());
})
</script>
</body>
</html>
要放在localhost下面使用
转载于:https://blog.51cto.com/smilezhuolin/1369046
本文介绍如何在本地环境下使用jQuery和iframe来测试HTML文档,包括引入jQuery库,创建iframe元素,并通过jQuery获取iframe内部元素的内容。

被折叠的 条评论
为什么被折叠?



