自动完成,同时使用 jquery 和 jquery UI 版本
我想知道javascript是否可以看到jquery的autocomplete()和jquery UI的autocomplete()之间的区别。
http://jqueryui.com/demos/autocomplete/
http://docs.jquery.com/Plugins/Autocomplete
我正在使用这两个版本,并且 atm 仅适用于 jquery 版本。这是由于语法错误还是因为这些函数不能一起使用?
$("#auto").autocomplete($("#base_uri").val()+'ajax/search',{
req_type: "POST",
minChars: 1,
delay: 200
}).result(function(event, data, formatted) {
$("#message-add").hide();
$("#auto").show();
$("#auto").focus();
$("#fake_to").append('<span id="'+data[1]+'">'+formatted+', '+'</span>');
$("#to").val($("#to").val()+ data[1] +', ');
$("#auto").val('');
});
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
I wonder if javascript can see the difference between the autocomplete() of jquery and the autocomplete() of jquery UI.
http://jqueryui.com/demos/autocomplete/
http://docs.jquery.com/Plugins/Autocomplete
I am using both versions and atm only the jquery one works. Is this due to syntax errors or because the functions can't be used together??
$("#auto").autocomplete($("#base_uri").val()+'ajax/search',{
req_type: "POST",
minChars: 1,
delay: 200
}).result(function(event, data, formatted) {
$("#message-add").hide();
$("#auto").show();
$("#auto").focus();
$("#fake_to").append('<span id="'+data[1]+'">'+formatted+', '+'</span>');
$("#to").val($("#to").val()+ data[1] +', ');
$("#auto").val('');
});
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信同时使用这两者会导致冲突。想一想——两者都采用
$.fn.autocomplete
函数。换句话说,您最后添加的可能是您唯一可以使用的。
我建议一次只使用一个。事实上,非 jQueryUI 版本的作者建议您使用 jQueryUI 版本,因为他的版本已被弃用,取而代之的是该版本:
原版中有一些不错的功能未包含在 jQueryUI 中,但我认为您可以实现其中大部分功能(以及实现这些功能的方法已在 StackOverflow 上作为问题提出并回答)。
I'm sure using both of these will cause a conflict. Think about it--both take the
$.fn.autocomplete
function.In other words, the one you include last will probably be the only one you can use.
I would recommend only using one at a time. In fact, the author of the non-jQueryUI one recommends that you use the jQueryUI version, as his version has been deprecated in favor for that one:
There are a few nice features in the original that were not included in the jQueryUI one, but I think you can accomplish most of those features (and ways to do that have been asked as questions and answered here on StackOverflow).