有谁知道如何在'MYCODE'中集成自定义类?我好像有
一个工作片段,但不确定它到底在哪里。
任何帮助表示赞赏。谢谢。
该片段正在处理jsfiddle http://jsfiddle.net/andrewwhitaker/rMhVz/2/
片段:
$("input").autocomplete({source: data}).data("autocomplete")._renderItem = function(ul, item) {
var listItem = $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
if (item.class != "") {
listItem.addClass(item.class);
}
return listItem;
};
MYCODE:
$( "#phraseId" ).bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).autocomplete( "instance" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
source: function( request, response ) {
$.getJSON( "search.php", {
term: extractLast( request.term )
}, response );
},
search: function() {
// custom minLength
var term = extractLast( this.value );
if ( term.length < 2 ) {
return false;
}
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( " " );
return false;
}
});
});