Jquery 自动完成关闭功能

发布于 2025-01-07 16:14:23 字数 760 浏览 0 评论 0原文

我有一个 Jquery 自动完成菜单,底部有一个图像 - 添加了下面的代码。

有没有办法让 Jquery 自动完成菜单在我单击图片后关闭(消失)?

感谢您的帮助。

<script>
$(function() {
       var availableTags = [
        "new york, ny",
        "new york city, ny",
        "manhattan, ny",
        "queens, ny",
        "brooklyn, ny",
        "bronx, ny",
        "staten island, ny",
        "kings county, ny",
        "richmond county, ny",
        "big apple, ny" 
    ];
    $( "#tags" ).autocomplete({ 
        source: availableTags,
        open: function (event, ui) { 
                     var nyc="<img src=\"images/iloveny.jpg\" onclick=\"DoGood()\"/>";
                     $(this).autocomplete("widget").append(nyc); 
            },
    });
}); 
</script> 

I have a Jquery Autocomplete menu with an image at the bottom of it - added with the code below.

Is there a way to have Jquery Autocomplete menu close (disappear) after I click on the picture?

Thank you for your help.

<script>
$(function() {
       var availableTags = [
        "new york, ny",
        "new york city, ny",
        "manhattan, ny",
        "queens, ny",
        "brooklyn, ny",
        "bronx, ny",
        "staten island, ny",
        "kings county, ny",
        "richmond county, ny",
        "big apple, ny" 
    ];
    $( "#tags" ).autocomplete({ 
        source: availableTags,
        open: function (event, ui) { 
                     var nyc="<img src=\"images/iloveny.jpg\" onclick=\"DoGood()\"/>";
                     $(this).autocomplete("widget").append(nyc); 
            },
    });
}); 
</script> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

留一抹残留的笑 2025-01-14 16:14:23

在点击事件上,调用 $( "#tags" ).autocomplete( "close" );

这是我的做法...

$("#tags").autocomplete({
    source: availableTags,
    open: function(event, ui) {

        var nyc = $("<img />", {
            src: "http://www.gravatar.com/avatar/8a3efc8be996c87da020df31e2416151?s=32&d=identicon&r=PG",
            alt: ""
        });

        nyc.click(function() {
            $(event.target).autocomplete("close");
        });

        $(this).autocomplete("widget").append(nyc);
    }
});​

jsFiddle

On the click event, call $( "#tags" ).autocomplete( "close" );.

Here is how I'd do it...

$("#tags").autocomplete({
    source: availableTags,
    open: function(event, ui) {

        var nyc = $("<img />", {
            src: "http://www.gravatar.com/avatar/8a3efc8be996c87da020df31e2416151?s=32&d=identicon&r=PG",
            alt: ""
        });

        nyc.click(function() {
            $(event.target).autocomplete("close");
        });

        $(this).autocomplete("widget").append(nyc);
    }
});​

jsFiddle.

千鲤 2025-01-14 16:14:23

我是这样做的:

function closeAutocomplete() {
    $("#tags").next().hide();
}


$(function() {
       var availableTags = [
        "new york, ny",
        "new york city, ny",
        "manhattan, ny",
        "queens, ny",
        "brooklyn, ny",
        "bronx, ny",
        "staten island, ny",
        "kings county, ny",
        "richmond county, ny",
        "big apple, ny" 
    ];
    $( "#tags" ).autocomplete({ 
        source: availableTags,
        open: function (event, ui) { 
                     var nyc="<img id=\"nycImage\" src=\"https://twimg0-a.akamaihd.net/profile_images/772597407/DCA_Twitter_normal.png\" />";

                     $(this).autocomplete("widget").append(nyc); 
                     $('#nycImage').click(closeAutocomplete);
            },
    });
}); 



​

Here's how I did it:

function closeAutocomplete() {
    $("#tags").next().hide();
}


$(function() {
       var availableTags = [
        "new york, ny",
        "new york city, ny",
        "manhattan, ny",
        "queens, ny",
        "brooklyn, ny",
        "bronx, ny",
        "staten island, ny",
        "kings county, ny",
        "richmond county, ny",
        "big apple, ny" 
    ];
    $( "#tags" ).autocomplete({ 
        source: availableTags,
        open: function (event, ui) { 
                     var nyc="<img id=\"nycImage\" src=\"https://twimg0-a.akamaihd.net/profile_images/772597407/DCA_Twitter_normal.png\" />";

                     $(this).autocomplete("widget").append(nyc); 
                     $('#nycImage').click(closeAutocomplete);
            },
    });
}); 



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