您可以尝试像这样覆盖 updateChoices 方法:
Ajax.Autocompleter.prototype.updateChoices = function (choices) {
if(!this.changed && this.hasFocus) {
if(!choices) {
//do your "new item" thing here
}
else {
this.update.innerHTML = choices;
Element.cleanWhitespace(this.update);
Element.cleanWhitespace(this.update.down());
if(this.update.firstChild && this.update.down().childNodes) {
this.entryCount =
this.update.down().childNodes.length;
for (var i = 0; i < this.entryCount; i++) {
var entry = this.getEntry(i);
entry.autocompleteIndex = i;
this.addObservers(entry);
}
} else {
this.entryCount = 0;
}
this.stopIndicator();
this.index = 0;
if(this.entryCount==1 && this.options.autoSelect) {
this.selectEntry();
this.hide();
} else {
this.render();
}
}
}
}
在controls.js 中覆盖不是一个好主意。相反,您可以将其添加到新的 .js 中,并将其包含在库之后。
编辑:pff .. 抱歉缩进不好,但它是从 TextMate 复制/粘贴的,并且有制表符和空格。我希望你明白这一点。我唯一添加的是
if(!choices) {
//do your "new item" thing here
}
else {}
堵塞。另外,我没有测试代码,但我认为它应该可以工作。