2012-01-26 123 views
0

我試圖附加一個簡單的點擊事件與jQuery自動完成。這是代碼即時通訊使用:jquery點擊事件與自動完成

$("#term").autocomplete({ 

    source: function(request, response) { 
    $.ajax({ 
     url: 'http://query.yahooapis.com/v1/public/yql', 
     dataType: 'JSONP', 
     data: { 
     format: 'json', 
     q: 'select * from xml where url="http://google.com/complete/search?output=toolbar&q=' + escape(request.term) + '"' 
     }, 
     success: function(data) { 
     response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) { 
      return { label: item.suggestion.data, value: item.suggestion.data }; 
     })); 
     } 
    }); 
    } 
}); 

我想可以點擊列表中的項目,然後將觸發另一個請求(EA填充另一個列表)我想用jQuery的單擊事件要做到這一點,到目前爲止,不好,看到這個LINK

+0

我有一個類似的問題做到這樣。發佈[這裏]答案[1] [1]:http://stackoverflow.com/questions/8158246/firing-the-select-event-on-click-for-jquery-autocomplete/12220921 #12220921 –

回答

3

你可以在自動完成中使用select事件。

$("#term").autocomplete({ 
    select:function(event, ui){ 
      // do your things here 
     }, 

    source: function(request, response) { 
    $.ajax({ 
     url: 'http://query.yahooapis.com/v1/public/yql', 
     dataType: 'JSONP', 
       data: { 
     format: 'json', 
     q: 'select * from xml where url="http://google.com/complete/search?output=toolbar&q=' + escape(request.term) + '"' 
     }, 
     success: function(data) { 
     response($.map(data.query.results.toplevel.CompleteSuggestion, function(item) { 
      return { label: item.suggestion.data, value: item.suggestion.data }; 
     })); 
     } 
    }); 
    } 
}); 

要不然你可以在你的方式

$(".ui-menu-item a").on('click',function() { 

看到它的工作here

+0

我已經嘗試過了(我沒有使用javascript) – Youss

+0

啊,它應該工作! –

+0

我知道...我試過這樣的事情:'$(「li a」)。click();' – Youss