jQuery UI Autocomplete控件下拉列表固定高度
2017-04-11 15:13
501 查看
jQuery ui Autocomplete控件下拉列表高度默认是自适应的,有多少数据就会加载出来多少行。以下是给下拉列表设置一个默认高度并添加滚动条的解决办法。
在样式里添加以下代码
官方源码[http://jqueryui.com/autocomplete/#maxheight ]
在样式里添加以下代码
.ui-autocomplete { max-height: 150px; //默认最大高度150像素 overflow-y: auto; //添加滚动条 /* prevent horizontal scrollbar */ overflow-x: hidden; } /* IE 6 doesn't support max-height * we use height instead, but this forces the menu to always be this tall */ * html .ui-autocomplete { height: 150px; //解决IE6下不识别max-height }
官方源码[http://jqueryui.com/autocomplete/#maxheight ]
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Autocomplete - Scrollable results</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
.ui-autocomplete { max-height: 150px; //默认最大高度150像素 overflow-y: auto; //添加滚动条 /* prevent horizontal scrollbar */ overflow-x: hidden; } /* IE 6 doesn't support max-height * we use height instead, but this forces the menu to always be this tall */ * html .ui-autocomplete { height: 150px; //解决IE6下不识别max-height }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
} );
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
相关文章推荐
- jqueryui autocomplete 控件自定义source检索
- 邮箱自动下拉匹配列表jQuery插件mailAutoComplete实例页面
- jquery ui autocomplete自动提示控件使用示例
- jquery ui tabs 控件 标签倒置并实现固定
- 使用 jQuery UI AutoComplete
- jQuery UI Autocomplete 体验分享
- jQuery 的下拉列表日期控件
- jQuery插件 - 下拉列表日期选择控件
- jQuery UI Autocomplete 类似百度、谷歌输入框的自动填充文本域
- jQuery UI AutoComplete 自动完成使用小记
- jQuery UI Autocomplete 体验分享
- jQuery UI Autocomplete 体验
- Asp.net MVC 3+ Jquery UI Autocomplete实现百度效果
- jQuery UI Autocomplete
- jQuery UI Autocomplete 1.8.16 中文输入修正代码
- JQUERY UI autocomplete
- jQuery UI Autocomplete 使用 ajax 方法传输Json数据出现乱码问题的解决
- jQuery UI AutoComplete 使用小记
- jQuery UI AutoComplete 使用说明
- 修复jQuery UI Autocomplete在firefox不支持中文的BUG