我有一个下拉菜单,用户可以从中选择值。它目前是用一个表生成的,其中每个选项都是表中的一个。我知道使用元素会更好,但此时更改为需要大量工作。
下拉菜单显示 6 行,并使用“溢出:滚动”允许用户向下滚动以查看其余选项。
目前,当用户选择下拉菜单时,滚动条总是从顶部开始,如果他们想选择其中一行,他们必须向下滚动到列表的底部。
我想要的是一种让滚动条从他们之前选择的元素开始的方法。我知道用户之前选择的行号,并且可以使用它来计算滚动条在加载时应该向下移动的像素数。
具体的 HTML 代码并不太重要,因为我相信这个想法可以推广到很多情况,但这是我现在正在使用的内容:一些元素丢失了,因为它们是在运行时动态生成的,但是您应该能够大致了解我正在使用的内容。
<table cellspacing="0" cellpadding="2" style="width: 100%;>
<colgroup>
<col class="select_htc_col" style="font-size: 11px;">
</colgroup>
<tbody>
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
<tr style="height: 19px;">
</tbody>
</table>
我觉得应该有一些 CSS 属性来让滚动条不从顶部开始。
另一个想法是给每个人一个 ID,并以某种方式显示元素。
谢谢!