当我的按钮被点击时,我有一个指向锚点的onClick函数。当你点击按钮时,你可以看到#出现在url中,页面很快跳转到锚点,但是url中的#消失了,页面跳回到顶部。我想知道是否有人知道这是什么原因,以及如何修复它,使页面停留在锚点。
<button type="submit" class="btn btn-primary" name='search' onClick="location.href='index.php#results'">Search</button>
然后在这页的后面..。
<a id="results"></a>
发布于 2018-07-01 06:52:31
你需要在<a>
标签中使用按钮
<a href="index.php#results">
Search <button type="submit" class="btn btn-primary" name='search' />
</a>
https://stackoverflow.com/questions/51119111
复制相似问题