2016-02-22 63 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> 
相关问题