2013-10-03 31 views
0

新的php :)PHP:如何鏈接一個帶有HTML部分的URL?

在博客項目上工作時,我想通過點擊索引頁面上的「評論」鏈接將用戶導航(發送)到具有特定(完整)帖子及其評論的其他頁面。

我希望將用戶直接發送到評論div。但我也必須在問號「?」後面提供帶有鏈接的帖子ID。我想知道在url中包含#comments div(html部分)的位置。

預先感謝您。

回答

0

首先,將id分配給您希望瀏覽器(用戶)滾動到的元素。

Ex。

<div id="mycomment"> 

然後,產生與#追加和id您選擇的網址。

Ex。

http://example.com/post/1/#mycomment 
0

名稱添加到一個錨定標記<a name='anchor1'>並鏈接使用前綴#<a href='#anchor1'>Comment</a>

<a href="#anchor1">First</a> | 
<a href="#anchor2">Second</a> | 
<a href="#anchor3">Third</a> | 
<a href="#anchor4">Forth</a> | 
<a href="#anchor5">Fifth</a> 

<a name='anchor1'>First comment header</a> 
<p>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br>First comment content<br></p> 

<a name='anchor2'>Second comment header</a> 
<p>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br>Second comment content<br></p> 

<a name='anchor3'>Third comment header</a> 
<p>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br>Third comment content<br></p> 

<a name='anchor4'>Fourth comment header</a> 
<p>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br>Fourth comment content<br></p> 

<a name='anchor5'>Fifth comment header</a> 
<p>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br>Fifth comment content<br></p> 

如果評論細節在其它頁面中調用它作爲

<a href="other_page.php#anchor1">First</a> | 
<a href="other_page.php#anchor2">Second</a> | 
<a href="other_page.php#anchor3">Third</a> | 
<a href="other_page.php#anchor4">Forth</a> | 
<a href="other_page.php#anchor5">Fifth</a> 
到HREF