使用iframe能很好的嵌入其他的網(wǎng)頁或者網(wǎng)站,但是iframe每次加載都會(huì)浪費(fèi)好多的時(shí)間,且會(huì)阻止其他元素的加載,搜索引擎也不能識(shí)別頁面ifram框架中被調(diào)用的鏈接、文本、圖片等等內(nèi)容的。
Html代碼
< ul class="list-side">
< li >< a target="a.html" >about</ a ></ li >
< li >< a target="b.html" >news</ a ></ li >
< li >< a target="c.html" >product</ a ></ li >
</ ul >
< div id="iframe">
<!--jquery 插入html 位址-->
</ div >
|
實(shí)現(xiàn)功能的Javascript代碼
$(document).ready( function (){
$.get( "a.html" , function (data){ //初始將a.html include div#iframe
$( "#iframe" ).html(data);
});
$( function (){
$( '.list-side li' ).click( function () {
// 找出 li 中的超鏈接 href(#id)
var $ this = $( this ),
_clickTab = $ this .find( 'a' ).attr( 'target' ); // 找到鏈接a中的targer的值
$.get(_clickTab, function (data){
$( "#iframe" ).html(data);
});
});
});
|
|