2016-02-22 65 views
0

如果我想在我的主頁上的一個部分作爲傳情給不同頁面上的文章,下面的標記是正確的嗎?如何從其他頁面加載文章`articles.php`到另一個頁面,即`index.html`

<section> 
     <article> 
     <a href=""> 
      <img src="" alt=""> 
      <h1></h1> 
      <p></p> 
     </a> 
     </article> 
    </section> 
+0

您是什麼意思的傳情?請詳細說明。你的問題對我來說很模糊。或者你的意思是你想包括一個文章頁面到你的主頁? –

+0

我想在我的主頁上創建一篇文章的摘錄,該文章鏈接到不同頁面上的完整文章。 – Benny

+0

請參考下面的答案,看看它是否適合你 –

回答

0

讓我們假設這是您的主頁index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>HOME PAGE</title> 
</head> 

<body> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script> 

<script type="text/javascript"> 
$(function() { 
    $("#list").addClass('loader'); 
    $("#list").load('article.php', function() { 
     $("#list").removeClass('loader'); 
    }); 

}); 

</script> 
<style> 
.loader{ 
    background-image:url(loader.gif); 
    background-repeat:no-repeat; 
    background-position:center; 
    height:10px; 
} 
</style> 

<!--and this is where you want the articles to appear--> 
<div id="list"></div> 
</body> 
</html> 

這是你的文章頁:article.php

<section> 
     <article> 
     <a href=""> 
      <img src="" alt=""> 
      <h1>Heading</h1> 
      <p>article</p> 
     </a> 
     </article> 
</section> 

而且如果物品是在特定<div><article>。然後給<div><article>一個ID,例如<div id="divID" ><article id="divID" >並使用此JavaScript加載代碼代替

<script type="text/javascript"> 
    $(function() { 
     $("#list").addClass('loader'); 
     $("#list").load('article.php #divID', function() { 
      $("#list").removeClass('loader'); 
     }); 

    }); 

</script> 
相關問題