sac*_*ith 1 javascript jquery jquery-ui
这几乎是这个问题的逐字帖.但是,一旦你转到jQuery 1.10,代码就不再有用了.
我确实将调用更改为"实时"方法,并将其切换为使用较新的"on"方法.我还需要做些什么来修复这个http://jsfiddle.net/sacredfaith/6t74T/458/?
$(function() {
var options = {
source: [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
],
minLength: 2
};
$(document.body).on("keydown.autocomplete", "input.searchInput",function(){
$(this).autocomplete(options);
});
var addInput = function() {
var inputHTML = " <input name='search' value='' class='searchInput' maxlength='20' />";
$(inputHTML).appendTo("form#myForm");
$("input.searchInput:last").focus();
};
if (!$("form#myForm").find("input.searchInput").length) {
addInput();
}
$("input#addButton").click(addInput);
});
Run Code Online (Sandbox Code Playgroud)
到目前为止,我的搜索已经产生了使用弃用的jquery库的方法.我需要一个更新的版本,但在过去几个小时的工作中未能找到成功......
编辑:小提琴链接和代码更新,以反映"on"语法更改.
EDIT2:感谢您的耐心等待.
参考:对于1.10解决方案,请参阅所选答案的评论中的小提琴,否则使用1.9,直接在所选答案中查看小提琴.
你没有包含jquery ui库,也像动态元素一样使用它
$(document.body).on('focus', 'input.searchInput' ,function(){
$(this).autocomplete(options);
});
Run Code Online (Sandbox Code Playgroud)