【发布时间】:2015-07-09 21:11:04
【问题描述】:
我有以下带有 iframe 的 HTML 代码:
<body>
<a href="#">example 1</a>
<div style="width:150px;">example 2</div>
<br><br>
<iframe align="center" width="80%" height="90%" src="test.html" frameborder="yes" scrolling="yes" name="myIframe" id="myIframe"> </iframe>
</body>
test.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>TODO write content</div>
<br>
<div>div content</div>
</body>
</html>
然后我写了一个jQuery代码来查找div标签并突出显示
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script lang="text/javascript">
$(document).ready(function(){
var iframe = $('#myIframe');
iframe.load(function(){
iframe.ready(function(){
$(document).on('mouseover', 'div', function (e) {
$(this).addClass('highlight');
});
$(document).on('mouseout', 'div', function (e) {
$(this).removeClass('highlight');
});
}); // end iframe load
});// end iframe ready
});
</script>
这在 iframe 之外的 div 中有效。我需要突出显示 iframe 内部的 div。
【问题讨论】: