【发布时间】:2020-03-28 13:52:01
【问题描述】:
请在此处查看我的表格。 https://business-sale.com/daily-companies-finance-alerts#dfa-form
正如您在单击下拉菜单时看到的那样,下拉菜单向上打开(而不是向下)并将用户带到页面顶部。这是有问题的,特别是如果用户使用小屏幕。我认为原因是它有太多选择。我的选择下拉框中有近 1000 个选项。我想将可见选项限制为 10。并使下拉框可滚动。
我试过了
<select class="selectpicker" id="sector" name="sector" multiple
style="height: 10px; overflow-y: scroll;"
data-live-search="true"
onfocus="this.size=10;">
和
<select class="selectpicker" id="sector" name="sector" multiple
style="height: 10px; overflow-y: scroll;"
data-live-search="true"
onmousedown="if(this.options.length>8){this.size=8;}">
但它不起作用。
其余代码请看这里
https://jsfiddle.net/bashabi/8fqmuyea/5/
如何解决
【问题讨论】:
-
可能不相关,但该页面在单击下拉列表时抛出错误:
dropdowntoggle.js:1 Uncaught TypeError: Cannot read property 'style' of null at toggleDropDown (dropdowntoggle.js:1) at HTMLDivElement.onclick (VM149 daily-companies-finance-alerts:174) -
既然您使用的是引导程序,为什么不使用他们的自定义下拉菜单? refer to this answer
标签: javascript css select html-select dropdownbox