开发者

How would I jump to a point in a page using the hash or pound symbol(#) with a get variable?

I found this tutorial that explains what I want to do using html but when I echo out the code with a get variable there is no affect to the 开发者_运维问答page. I would use, for example, the following code:

echo "<a href='post.php?id=".$id."#Comments'>Click here to go to the comments</a>";



echo "<a title='Comments'>Comments</a>";

I presume the problem is to do with the get variable, so would I have to end it, some how, before using the # symbol?


The problem actually lies in your HTML, because the anchor should be parsed correctly by browsers regardless of the query string.

Page anchors use the name attribute instead of the title attribute:

<a name='Comments'>Comments</a>

You can also apply this to the id attribute of any element:

<h2 id='Comments'>Comments</h2>


To define jump-labels you have to set a name and/or id-attribute:

echo "<a title='Comments' name='Comments' id='Comments'>Comments</a>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜