簡體   English   中英

jQuery自動完成結果到自定義下拉列表(在select選項標簽處)

[英]jQuery autocomplete results to a custom drop down list (at select option tags )

我想在選擇選項標簽中顯示我的自動完成結果,而不是在默認情況下顯示的ul li,其中添加了一些jquery類(我不是很想要)。

我在堆棧溢出中使用了一篇來自相關文章的代碼: http : //jsfiddle.net/naveen/yRwH7/作為示例。

實際上,它第一次正確加載,但此后沒有任何加載。 有什么建議么? 還有其他方法嗎? 代碼在這里http://jsfiddle.net/yRwH7/1/

Java腳本

 $("input#selectedInput").bind("autocompleteselect", function (event, ui) {
      alert("Sel item " + JSON.stringify(ui.item.json));
 }).autocomplete({
 appendTo: "#list",
 source: function (request, response) {

     $.ajax({
         url: "http://itunes.apple.com/search?term=jack+johnson&entity=musicTrack",
         dataType: "jsonp",
         data: {
             featureClass: "P",
             style: "full",
             maxRows: 12,
             name_startsWith: request.term
         },

         success: function (data) {
             response($.map(data.results, function (item) {
                 itunesJson = item;
                 return {
                     label: "<option>" + item.trackName + "</option>",
                 }
             }));
             var elm = $("#list");
             elm.html(elm.text());
         },
     });
 }
 })​

的HTML

<input type="text" id="selectedInput"/>
<select id="list"></select>

我嘗試了演示並對其進行了修改

正在使用Firefox

這是鏈接工作演示

div后看起來需要空格,可能是瀏覽器兼容性問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM