如何限制数据列表的显示大小?
我有一个包含一堆数字的数据列表,并且想将菜单的显示大小限制为 5 个选项,但据我所知,这不能用 html/css 来完成,那么我的选项是什么?
// Generate an array from 1-144 in increments of 0.5
var length = [];
var list = document.getElementById('lengthDatalist');
for (let i = 1; i <= 144; i+= 0.5) {
length.push(i.toFixed(1));
};
//For each item in array length, create an option in datalist
length.forEach(function(item){
var option = document.createElement('option');
option.value = item;
list.appendChild(option);
});
<input name= "lengthInput" id="lengthInputID" list="lengthDatalist" />
<datalist id="lengthDatalist"></datalist>
I have a datalist with a bunch of numbers and would like to limit the display size of the menu to 5 options, but as I understand this can't be done with html/css, so what are my options?
// Generate an array from 1-144 in increments of 0.5
var length = [];
var list = document.getElementById('lengthDatalist');
for (let i = 1; i <= 144; i+= 0.5) {
length.push(i.toFixed(1));
};
//For each item in array length, create an option in datalist
length.forEach(function(item){
var option = document.createElement('option');
option.value = item;
list.appendChild(option);
});
<input name= "lengthInput" id="lengthInputID" list="lengthDatalist" />
<datalist id="lengthDatalist"></datalist>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论