根据你对 Haim 帖子的评论,你想要的可以简化为:
$('#reload').click(function() {
$('#f1').attr('src', $('#f1').attr('src'));
return false;
});
或者
$('#reload').click(function() {
$('#f1')[0].contentWindow.location.reload(true);
return false;
});
但也许他的回答更适合您的需求。
更新:
我使用上面提供的方法组合了一个可工作的示例。我在一个页面中有一个<iframe>
,它显示另一个打印时间的页面。
<iframe>
HTML 代码(time.html):
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
The time is now <span id="time"></span>.
<script type="text/javascript">
$(document).ready(function() {
$('#time').html((new Date()).toString());
});
</script>
</body>
还有父页面的HTML(test.html):
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<iframe id="frame" src="file:///D:/Users/Cory/Desktop/time.html" width="500" height="250"></iframe>
<button id="reload">Refresh</button>
<script type="text/javascript">
$(document).ready(function() {
$('#reload').click(function() {
$('#frame').attr('src', $('#frame').attr('src'));
return false;
});
});
</script>
</body>
在Firefox 3.6和IE 7中,这对我来说完全有效。