POST表单提交后使用锚


Use Anchor after POST Form Submission

我需要让页面在用户点击Post按钮后在页面内的特定标签加载

注意:我使用PHP

表单代码示例:

<form action="po.php?id=44" method="POST">
   <input type="hidden" name="here" value="#here" />
   <input name="btn_send" type="submit" value="Post" />
</form>

页面应该降落在页面的某个地方,在

之间有一个标题,如下所示

代码示例:

<a name="here"></a>
<p>Total Number of Posts 55</p>

如你所见,它的位置是一个常规的标签文本,而不是超链接。因此,我将锚行作为指示符放在标题前面。

问题:

页面没有着陆,我把(name="这里")。这一页落到了最上面。是否有简单的方法使它降落在(name="here")?

只需将片段包含在表单的action属性中,例如

<form method="post" action="po.php?id=44#here">

此外,使用ID属性作为片段位置要好得多。删除空锚点,将段落改为…

<p id="here">Total number of Posts 55</p>

试试这个:

<form action="po.php?id=44#here" method="POST">
   <input name="btn_send" type="submit" value="Post" />
</form>

把这个放到目标页面上:

<a id="here"></a>
<p>Total Number of Posts 55</p>
header("Location: url#fragment");