jquery - 将 jQuery 自动完成项呈现为内联 block

标签 jquery css jquery-ui autocomplete jquery-ui-autocomplete

我想使用 jQuery 自动完成功能显示一组功能结果(例如,能够使用箭头键进行选择),但我希望它们显示为 inline-block<,而不是在普通列表中显示结果.

这是我的代码。

$( "#people_q" ).autocomplete({
        minLength: 0,
        source: projects,
        focus: function( event, ui ) {
            $( "#people_q" ).val( ui.item.label );
            return false;
        },
        select: function( event, ui ) {
            $( "#people_q" ).val( ui.item.label );
            $( "#people_q-id" ).val( ui.item.value );
            $( "#people_q-description" ).html( ui.item.desc );
            $( "#people_q-icon" ).attr( "src", "images/" + ui.item.icon );

            return false;
        }
    })
    .data( "autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
            .appendTo( ul );
    };
});

这是我尝试过的样式。

<style>
    .ui-autocomplete {
    width:600px !important;
}

    .ui-menu-item {
        width:200px !important;
        display:inline !important;  
        }
</style>

最佳答案

UL 宽度在自动完成脚本中内联设置,这超出了您的 css 规则。你可以这样骑:

$(selector).data("autocomplete")._resizeMenu=function() {
      /* do nothing and will be width of page*/
       $.noop();
      /* OR set width */
     var ul = this.menu.element;
      $(ul).width(600);
};

演示:http://jsfiddle.net/M92kX/2/

关于jquery - 将 jQuery 自动完成项呈现为内联 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13331544/

相关文章:

javascript - 为什么画外音总是从现场区域的开头开始朗读?

java - 给定一个 bySelector 我怎样才能得到这个元素的 child 的选择器?

javascript - 手动或以编程方式单击时与 Prop ('checked' 不一致)

javascript - WheelNav 不适用于 CodePen,但在代码片段中

javascript - 使用 javascript 生成的 html 代码不适用于 jquery sortable

ruby-on-rails - Rails 3.2.8 中 Twitter Bootstrap 和 jQuery.ui 冲突

javascript - 在选择菜单上使用统一代码

html - 显示 flex 中表情符号 img 标签的 Css

html - 如何使用 Bootstrap 打印没有水平滚动条的换行文本?

css - 在 VS 中发布网站时 @import "theme.css"不起作用