gpt4 book ai didi

javascript - 如何使选择框下拉菜单变短

转载 作者:行者123 更新时间:2023-11-27 23:56:05 25 4
gpt4 key购买 nike

我的问题是,当我在选择框生日表单中选择年份和日期时,下拉列表太长了。我希望下拉菜单很短,但上面有一个滚动条。

html:

<div class="col-sm-offset-1 col-sm-12">
<div class="form-group input-group">
<div class="btn-group input-group">
<span class="input-group-addon">Birthday</span>
<select name="month" class="btn btn-default" id="bmonth" data-container="body" data-placement="left" data-toggle="popover" data-content="Select your Birthday!" >
<option>Month</option>
</select>
<select name="day" class="btn btn-default" id="bday" data-container="body" data-placement="top" data-toggle="popover" data-content="Select your Birthday!" >
<option>Day</option>
</select>
<select name="year" class="btn btn-default" id="byear" data-container="body" data-placement="right" data-toggle="popover" data-content="Select your Birthday!" >
<option>Year</option>
</select>
</div>
<br />
</div>
</div>

脚本:

$(document).ready(function () {
var month = [], day = [], year = [];

for (var i = 1; i <= 12; i++) {
month.push(i);
}
for (var i = 1; i <= 31; i++) {
day.push(i);
}
for (var i = 1900; i <= (new Date().getFullYear()); i++) {
year.push(i);
}
$.each(day, function (index, d) {
$("#bday").append("<option value = '"+d+"'>"+d+"</option>");
});
$.each(month, function (index, m) {
$("#bmonth").append("<option value = '"+m+"'>"+m+"</option>");
});
$.each(year, function (index, y) {
$("#byear").append("<option value = '"+y+"'>"+y+"</option>");
});
});

当前输出:

enter image description here

最佳答案

大小限制由浏览器控制,您无法更改。

正如这里的回答:

Height of an HTML select box (dropdown)

这里:

Limiting the displayed height of a select drop-down

关于javascript - 如何使选择框下拉菜单变短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com