新的php :)PHP:如何鏈接一個帶有HTML部分的URL?
在博客項目上工作時,我想通過點擊索引頁面上的「評論」鏈接將用戶導航(發送)到具有特定(完整)帖子及其評論的其他頁面。
我希望將用戶直接發送到評論div。但我也必須在問號「?」後面提供帶有鏈接的帖子ID。我想知道在url中包含#comments div(html部分)的位置。
預先感謝您。
新的php :)PHP:如何鏈接一個帶有HTML部分的URL?
在博客項目上工作時,我想通過點擊索引頁面上的「評論」鏈接將用戶導航(發送)到具有特定(完整)帖子及其評論的其他頁面。
我希望將用戶直接發送到評論div。但我也必須在問號「?」後面提供帶有鏈接的帖子ID。我想知道在url中包含#comments div(html部分)的位置。
預先感謝您。
您可以使用空<a>
標籤來做到這一點:
您的意見<div>
前粘貼此:
<a name="comments"></a>
,並嘗試與#comments標籤進入你的頁面,如:http://mysite.com/example.php?postID=123#comments
首先,將id
分配給您希望瀏覽器(用戶)滾動到的元素。
Ex。
<div id="mycomment">
然後,產生與#
追加和id
您選擇的網址。
Ex。
http://example.com/post/1/#mycomment
名稱添加到一個錨定標記<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