简体   繁体   English

jQuery如何遍历自动完成并设置标题并在悬停时显示它

[英]jQuery How to iterate through autocomplete and set title and display it on hover

How can i loop through a dynamic list created by jquery autocomplete plugin... i need to loop through each element in the list and set the title of each value listed in the menu...the title should be the same name as the product name... 我该如何遍历由jquery自动完成插件创建的动态列表...我需要遍历列表中的每个元素并设置菜单中列出的每个值的标题...标题应该与产品名称相同名称...

the reason for doing this is because some text in the list is hidden using 这样做的原因是因为使用

overflow:hidden; 溢出:隐藏 style... 样式...

so when the user hovers over any element the javascript has to set the current name of the product to the tile attribute..so that when hovering it display the full product name... 因此,当用户将鼠标悬停在任何元素上时,javascript必须将产品的当前名称设置为tile属性。.以便在悬停时显示完整的产品名称...

How can i do this.... 我怎样才能做到这一点....

the code so far i tried, 到目前为止,我尝试过的代码

         jQuery.each(availableTags, function(index,value) {
             this.attr().title = document.getElementById("#").innerHtml;
         });

and this, 和这个,

         jQuery.each("#autocompid", function(index,value) {
             var value = $(this).val();
             $("#autocompid ul li").attr(title,value));
         });

and my autocomplete like this... 和我的自动完成这样...

http://jsfiddle.net/fewds/HwchC/8/ http://jsfiddle.net/fewds/HwchC/8/

try this code after your autocomplete was bind 自动完成绑定后,尝试此代码

$("#autocompid").data("autocomplete")._renderItem = function (ul, item) {
            return $("<li></li>")
                .data("item.autocomplete", item)
                .append($("<a/>").html(item.label).attr("title", item.label))
                .appendTo(ul);
        };

_renderItem is a function of autocomplete plugin and we are overriding that function here. _renderItem是自动完成插件的功能,我们在此重写该功能。

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

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