且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在用户忽略的jQuery自动完成建议检测

更新时间:2021-12-06 08:34:40

我也碰到过很有意思的答案。它涉及的jQuery插件如何管理自己的地位。当我看着萤火虫(带firequery)我发现,当我点击图标显示DOM节点的jQuery的属性(HTML标签)它表现都连接到一个DOM节点和连接到该插件的数据是整个自动完成参数。因此,我找到了解决办法。

I have come across very interesting answer. It deals with how jQuery plugins manages their status. As I was looking at firebug(with firequery) I found that when I clicked icon showing jQuery properties of a DOM Node(in HTML tab) it showed all the plugin data attached to a DOM Node and attached to that was entire autocomplete parameters. Thus I found the solution.

$('#test').autocomplete({
    change:function( event, ui ) {
        var data=$.data(this);//Get plugin data for 'this'
        if(data.autocomplete.selectedItem==undefined)
            alert("manual");
        else
            alert("selected");      
    }
});

自动完成什么做的是,如果我们从列表中选择,然后将selectedItem包含我们只是它的所有属性中选择的JSON对象。但是,如果我们preSS ESC或取消设置为null自动填充。

What autocomplete does is that if we select from list then selectedItem contains the JSON object we just selected with all its properties. But if we press ESC or Cancel the autofill it is set to null.