jQuery Include HTML、插入html、jquery替代iframe

阅读更多

使用jQuery來達到如iframe、asp include 和 php include 的效果

jQuery Include HTML、插入html、jquery替代iframe_第1张图片

 

jQuery能做到的比iframe連結另一個網頁html內容來的活用,使用css做樣式變化,也較有彈性。再次比較asp include 和 php include 這樣的方式無須使用以上asp和php伺服器就能達到你想要的include html。

下列程式變化更加入了選單(Menu list)做連結的切換,分別使用jquery include 
三個html網頁檔案(a.html、 b.html、c.html)。
希望這樣的方式能為您帶來好的幫助。

 

HTML



 

JQUERY

$(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); 
 });
})
})
});

參考至:http://ucmic.blogspot.com/2011/05/jqueryjquery-include-html.html

你可能感兴趣的:(html,jquery)