iframe非同步載入實現點擊左邊菜單載入右邊內容執行個體講解

來源:互聯網
上載者:User

關於iframe非同步載入,我們常用的大都是左邊功能表列右邊是內容頁面,要求我們不能左邊菜單不能重新整理的情況下,非同步載入右邊的內容頁面。

話不多說,做了一個執行個體大致是這樣的:

1、首先在你的項目中建立三個檔案如:

2、在Default頁面引入jquery檔案並在body中加入也下代碼:
複製代碼 代碼如下:
<div style="width: 20%; float: left">
<div id="butten" style="cursor: pointer;">
局部重新整理(架構載入頁面)
</div>
<div id="hidden" style="display: none">
我是隱藏的,點擊局部重新整理之後<br />
我就顯示,頁面載入我不會消失
</div>
</div>
<div id="page" style="width: 80%; float: right;">
<iframe src='1.htm' frameborder='0' style='border: 0; width: 100%; height: 99.4%;'>
</iframe>
</div>
<script type="text/javascript">
$(function () {
$("#butten").click(function () {
$("#hidden").show();
$("iframe").attr("src", "2.htm");
});
});
</script>

3、在1.htm和2.htm中隨便寫上什麼都行,甚至可以直接這樣寫(什麼html、title、body、title等均可不用寫):
1.htm:
複製代碼 代碼如下:
頁面一<br />
原始頁面

2.htm:
複製代碼 代碼如下:
頁面二<br />
架構載入的頁面

4、效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.