3

我的页面中有几个可折叠块(div),其中包含列表视图。列表很长(每个大约 100-200 个元素。)当我取消折叠块,向下滚动页面并单击/点击列表中的一个元素时,页面会滚动到顶部,然后再滑动到下一个页。

这种行为有点烦人,看起来不太好。我有什么办法可以防止这种行为?

如果您对我的帖子有任何其他问题,请随时问我。

提前致谢。

4

1 回答 1

1

如果您使用带有“#”作为href 的链接,它将跳转到页面顶部,但是如果您添加“return false;” 执行您的代码后,它不会跳起来。例子:

<script>
function test(){
alert('It works!'); // Just a simple function
}
</script>

<!-- Div to make the page scrollable -->

<div style="margin-top:1000px;height:1px;width:1px;"></div>

<a href="#" onClick="test(); return false;">Yay</a>
<!-- Triggering the test function and not jumping up to the top -->

我不确定这是否是你的想法。

于 2011-12-31T17:19:03.120 回答