【发布时间】:2014-01-21 10:01:32
【问题描述】:
这几乎是this 问题的逐字帖子。然而,一旦你切换到 jQuery 1.10,代码就不再工作了。
我确实将调用更改为“live”方法,并将其切换为使用较新的“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);
});
到目前为止,我的搜索已经产生了使用已弃用的 jquery 库的方法。 我需要更新的版本,但在过去几个小时的工作中一直未能成功...
编辑:更新小提琴链接和代码以反映“关于”语法更改。
EDIT2:感谢大家的耐心等待。
参考:对于 1.10 解决方案,请参阅所选答案的 cmets 中的小提琴,否则使用 1.9,请直接参阅所选答案中的小提琴。
【问题讨论】:
-
你在这里没有使用委托,语法略有不同,请检查文档,例如相当于 live() 是:
$(document).on("focus","input.searchInput", function() {...}); -
@sacredfaith:您可以在一行中完成这一切,无需委托。请看下面我的回答。
标签: javascript jquery jquery-ui