简体   繁体   English

jQuery自动完成结果到自定义下拉列表(在select选项标签处)

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

I want to show my autocomplete results in select option tags instead of the default which is ul li with some jquery classes added (which I don't really want). 我想在选择选项标签中显示我的自动完成结果,而不是在默认情况下显示的ul li,其中添加了一些jquery类(我不是很想要)。

I'm using a code from a relative post here in stack overflow: http://jsfiddle.net/naveen/yRwH7/ as an example. 我在堆栈溢出中使用了一篇来自相关文章的代码: http : //jsfiddle.net/naveen/yRwH7/作为示例。

It loads correctly the first time actually but after that, nothing. 实际上,它第一次正确加载,但此后没有任何加载。 Any suggestions? 有什么建议么? Is there any other way to do it? 还有其他方法吗? the code is here http://jsfiddle.net/yRwH7/1/ 代码在这里http://jsfiddle.net/yRwH7/1/

Javascript 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 的HTML

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

i tried the demo and modified it 我尝试了演示并对其进行了修改

am using firefox 正在使用Firefox

here is the link working demo 这是链接工作演示

looks it needed a space after div may be browser compatability issue div后看起来需要空格,可能是浏览器兼容性问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM