使用 jquery 自动完成和工具提示

发布于 2024-11-23 19:17:55 字数 1539 浏览 1 评论 0原文

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

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

发布评论

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

评论(2

感情废物 2024-11-30 19:17:55

它只是

http://docs.jquery.com/Plugins/autocomplete

以及一些 CSS 功能。您可以使用 Chrome > Inspector 来查看他们添加了什么样的样式来创建这样的 UI l&f

Edit

基本上它是 jquery 中的悬停绑定

$("li").hover(fn);< /code>

在这个例子中(wowhead.com)他们调用一个链接,它是自动完成 div 的一部分

<div class="live-search-icon" style="background-image: 
url(http://static.wowhead.com/images/wow/icons/small/inv_misc_head_dragon_black.jpg); ">
    <div>
       <a href="/item=19003" class=" q4">
        <i>Item</i>
        <span>Head of Nefarian</span>
       </a>
    </div>
</div>

,jquery 对 url 进行 .ajax() 调用,如下所示: /item=19003&power

返回的数据采用 json 格式

$WowheadPower.registerItem('18422', 0, {
name_enus: 'Head of Onyxia',
quality: 4,
icon: 'INV_Misc_Head_Dragon_01',
tooltip_enus: '<table><tr><td><b class="q4">Head of Onyxia</b><br /><!--bo-->Binds when picked up<br />Unique<br /><a href="/quest=7490" class="q1">This Item Begins a Quest</a><br />Requires Level 60<br />Item Level 60</td></tr></table><table><tr><td><span class="q">"The head of the Black Dragonflight\'s Brood Mother"</span></td></tr></table>'
});

,它们显示在 div 中,相对于鼠标指针位置定位,

我没有提取确切的代码,但有可能,它们的 .js 文件仅被压缩,不被混淆

It's just

http://docs.jquery.com/Plugins/autocomplete

with some CSS features. You can use Chrome > Inspector to see what kind of styles they added to create such UI l&f

Edit

Basically it's hover binding in jquery

$("li").hover(fn);

and in this example (wowhead.com) they call a link which is part of autocomplete div

<div class="live-search-icon" style="background-image: 
url(http://static.wowhead.com/images/wow/icons/small/inv_misc_head_dragon_black.jpg); ">
    <div>
       <a href="/item=19003" class=" q4">
        <i>Item</i>
        <span>Head of Nefarian</span>
       </a>
    </div>
</div>

and jquery does an .ajax() call to url like this: /item=19003&power

returned data are in json

$WowheadPower.registerItem('18422', 0, {
name_enus: 'Head of Onyxia',
quality: 4,
icon: 'INV_Misc_Head_Dragon_01',
tooltip_enus: '<table><tr><td><b class="q4">Head of Onyxia</b><br /><!--bo-->Binds when picked up<br />Unique<br /><a href="/quest=7490" class="q1">This Item Begins a Quest</a><br />Requires Level 60<br />Item Level 60</td></tr></table><table><tr><td><span class="q">"The head of the Black Dragonflight\'s Brood Mother"</span></td></tr></table>'
});

and they are displayed in div, positioned relative to mouse pointer position

i didn't extracted exact code, but it is possible, their .js files are only compressed, not obfuscated

夜吻♂芭芘 2024-11-30 19:17:55

您可以使用“title”属性:

    $(function() {
        //field desc -> is the "tooltip"
        var availableTags = [
            { label: "Choice1", value: "value1", desc: "descricao 1" },
            { label: "Choice2", value: "value2", desc: "descricao 2 bla bla bla" },
            { label: "Choice3", value: "value3", desc: "descricao 3 ble" },
            { label: "Choice4", value: "value4", desc: "descricao 4 bli bli bli" }
        ];
        $( "#tags" ).autocomplete({
            source: availableTags,
            focus: function( event, ui ) {
                $(".ui-autocomplete > li").attr("title", ui.item.desc);
            }
        });
    });

https://jsfiddle.net/m02suadf/

您可以找到其他示例在 Internet 上使用 jquery-ui 中的“工具提示”(在版本 1.9 中添加)。

You can use the "title" attribute:

    $(function() {
        //field desc -> is the "tooltip"
        var availableTags = [
            { label: "Choice1", value: "value1", desc: "descricao 1" },
            { label: "Choice2", value: "value2", desc: "descricao 2 bla bla bla" },
            { label: "Choice3", value: "value3", desc: "descricao 3 ble" },
            { label: "Choice4", value: "value4", desc: "descricao 4 bli bli bli" }
        ];
        $( "#tags" ).autocomplete({
            source: availableTags,
            focus: function( event, ui ) {
                $(".ui-autocomplete > li").attr("title", ui.item.desc);
            }
        });
    });

https://jsfiddle.net/m02suadf/

You can find others examples on Internet using the "tooltip" from jquery-ui (that was added in version 1.9).

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