2

我正在索引页面上制作一个包含 20 个不同问题的网页。用户在每个问题后单击“提交”。

<form action="./index.php" method="post" id="element">

然后将信息发布并发送到数据库。当然,这会使索引页面重新加载并显示在页面的最顶部。这使得很多滚动。

有没有办法让页面重新加载并向下滚动到它离开的地方?

4

2 回答 2

0

答案在这里找到:https ://stackoverflow.com/a/7983093/4101210

要使用锚来提交表单,需要使用 JavaScript 来连接事件。这是不安全的,如果用户禁用了 JavaScript,您将无法提交表单。例如:

<form id="form1" action="" method="post">
    <a href="#" onclick="document.getElementById('form1').submit();">Submit!</a>
</form>

如果您愿意,可以使用<button>

<button type="submit">Submit!</button>

或者坚持我们都知道的:

<input type="submit" value="Submit!" />

您可以设置所有三个样式,但后两个不需要 JavaScript。如果遇到边框问题,您可能只需要在某处更改一些 CSS。

于 2020-03-31T02:52:20.773 回答
0

回答我问题的代码是由 joshua bissot 编写的。他展示了如何将令牌放入动作中并命名锚点以使其工作。

https://stackoverflow.com/a/25918771/12140988

<!-- add the anchor token at the end of your action statement -->

<form method='post' action='this_page.php?put_peram=token#anchor_name'>
<input type='submit' value='click here'>

<!-- put the anchor right above where you want the page to  index -->

<a name="anchor_name></a>
于 2020-04-03T06:45:57.177 回答