我试图做使用jQuery UI库轨自动完成功能。 不过,我不断收到语法错误“语法错误:保留字‘功能’上线......”
这是我的lessons.js.coffee文件
jQuery ->
$(function() {
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
$( "#lesson_tag_name" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
source: $('#lesson_tag_name').data('autocomplete-source')
},
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;
}
});
});
我在网上读的地方,我可以用替换词功能 - >我这样做,我停止接收功能的错误,但后来我让其他的语法错误,如“语法错误:保留字‘VAR’上线......”
难道我做错了什么?