我使用iframe创建了一个动态加载页面。当它加载时,它会在主体区域显示空白区域,直到我单击页面链接。如何在I框架加载时添加默认页面。
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$(".divlink").click(function(){
$("#content").attr("src" , $(this).attr("ref"));
});
});
</script>
</head>
<body>
<iframe id="content"></iframe>
<a href="#" ref="page1.html" class="divlink" >Page 1</a><br />
<a href="#" ref="page2.html" class="divlink" >Page 2</a><br />
<a href="#" ref="page3.html" class="divlink" >Page 3</a><br />
<a href="#" ref="page4.html" class="divlink" >Page 4</a><br />
<a href="#" ref="page5.html" class="divlink" >Page 5</a><br />
<a href="#" ref="page6.html" class="divlink" >Page 6</a><br />
</body>
</html>发布于 2016-08-13 17:15:20
请检查下面的代码片段。在这种情况下,它将从第一个'a‘元素加载页面。
$(document).ready(function(){
$("#content").attr("src" , $("a.divlink:first").attr("ref"));
$(".divlink").click(function(){
$("#content").attr("src" , $(this).attr("ref"));
});
});发布于 2020-10-08 04:50:07
使用iframe src属性
<iframe id="content" src="page1.html"></iframe>
https://stackoverflow.com/questions/38931125
复制相似问题