自动完成,同时使用 jquery 和 jquery UI 版本

发布于 2024-11-18 04:12:31 字数 1706 浏览 0 评论 0原文

我想知道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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Hello爱情风 2024-11-25 04:12:31

确信同时使用这两者会导致冲突。想一想——两者都采用 $.fn.autocomplete 函数。

换句话说,您最后添加的可能是您唯一可以使用的。

我建议一次只使用一个。事实上,非 jQueryUI 版本的作者建议您使用 jQueryUI 版本,因为他的版本已被弃用,取而代之的是该版本:

注意(2010-06-23):这个插件是
已弃用且不再开发。
它的继承者是 jQuery UI 的一部分,
本迁移指南解释了如何
从这个插件到新的
一个。

原版中有一些不错的功能未包含在 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:

Note (2010-06-23): This plugin is
deprecated and not developed anymore.
Its successor is part of jQuery UI,
and this migration guide explains how
to get from this plugin to the new
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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文