JQuery UI自动完成 - 如何在选择项目时触发事件?

Mar*_*arc 4 jquery jquery-ui jquery-ui-autocomplete

我有一个输入字段和一个隐藏的div.输入是只读的.当用户单击输入时,使用JQuery UI自动完成建议项目列表.我想要和不想实现的是当用户从列表中选择一个项目时触发一个事件(删除隐藏的类).希望有人能提供帮助.提前感谢您的回复.干杯.渣.

http://jsfiddle.net/fdBHC/1/

我的HTML:

<input id="conditions" type="text" readonly="readonly" /input>
<div id="test" class="hidden">some text</div>?
Run Code Online (Sandbox Code Playgroud)

我的css:

input{
    margin:50px;
    border:1px solid black;}

div{
    width:200px
    height:200px;
    background-color:orange;}

.hidden{
    display:none;}
Run Code Online (Sandbox Code Playgroud)

我的js:

$(function() {
    var availableTags = [
            "aucune","Prise de contact préalable nécessaire"
        ];
    $("#conditions").autocomplete({
        source: availableTags,
        minLength: 0
    }).click(function() {
        $(this).val("");
        $(this).autocomplete("search");
    });
});?
Run Code Online (Sandbox Code Playgroud)

fre*_*ish 7

您可以使用自动填充程序中的事件(如果我理解正确的话):

$("#conditions").autocomplete({
    source: availableTags,
    minLength: 0,
    select: function(event, ui) {
        // do something when an item from the list is selected, for example:
        $('#test').remove();
    }
})...
Run Code Online (Sandbox Code Playgroud)

  • 你在'minLength:0`之后错过了一个逗号 (3认同)