이 이제 기본적인 요점은 이것이다이 Jquery-ui-Autocomplete Catagories
를 살펴 전적으로 가능하다 :
<style>
.ui-autocomplete-category {
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
}
</style>
<script>
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function(ul, items) {
var that = this,
currentCategory = "";
$.each(items, function(index, item) {
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
that._renderItemData(ul, item);
});
}
});
</script>
<script>
$(function() {
var data = [
{ label: "anders", category: "" },
{ label: "andreas", category: "" },
{ label: "antal", category: "" },
{ label: "annhhx10", category: "Products" },
{ label: "annk K12", category: "Products" },
{ label: "annttop C13", category: "Products" },
{ label: "anders andersson", category: "People" },
{ label: "andreas andersson", category: "People" },
{ label: "andreas johnson", category: "People" }
];
$("#search").catcomplete({
delay: 0,
source: data
});
});
</script>
</head>
<body>
<label for="search">Search: </label>
<input id="search" />
</body>
지금 당신이 무엇을 원하는 일반 아이디어를 얻기 위해 .ui-autocomplete-catagory
CSS 클래스를 변경하다 특정 카테고리가 다른 색상을 갖게하려면 자신의 CSS 클래스를 추가해야합니다. 위의 첫 번째 스크립트에서 ul.append()
의 각 카테고리 추가에 구체적으로 추가하도록 jQuery를 사용할 수 있습니다.