Jquery 自动完成扩展范围太广

标签 jquery css autocomplete

我正在使用 jquery 的自动完成功能,但长字符串导致建议框扩展得比输入字段更宽。您可以在此图片中看到它。

too wide suggestions list

在上图中,“(1450)”应放置在下一行。

我的jquery函数:

function autosuggest() {
    $( autocomplete_field ).autocomplete(
    {
         source: posturl,
         minLength:2,
         delay: 0
    });
};

CSS:

.ui-widget-content { background: #ffffff; }
.ui-helper-hidden-accessible { position: absolute; left: -9999px; }
.ui-autocomplete { border: 1px solid #abadb3; border-top: none; position: absolute; top: 0; left: 0; cursor: pointer; }
* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */
.ui-menu-item { list-style:none; margin: 0px; padding: 0px; border-bottom:1px dotted #000; }
.ui-menu-item a { display: block; padding: 6px; }
.ui-menu-item:last-child { border-bottom:none; }
.ui-menu-item  strong{ color: #003b63; }
.ui-state-focus { background-color: #aad9fb; color:#000; display: block; }

在jquery函数中,我尝试添加:

$('.ui-menu').css('max-width','178px')

这适用于屏幕截图中的字段,但我的网站上有许多宽度不同的自动完成字段,因此这不是一个选项。

我已经搜索了API的文档,但还没有找到解决方案。

最佳答案

尝试获取输入字段的宽度,然后将自动完成的最大宽度更改为该宽度。

关于Jquery 自动完成扩展范围太广,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23610331/

相关文章:

javascript - 如何仅在提交时显示 jQuery 验证错误容器

javascript - Jquery:无法将空格添加到 contenteditable div 的占位符

html - 你能设置有序列表编号的样式吗?

javascript - Google maps Places API V3 自动完成 - 在输入时选择第一个选项(并保持原样)

页面中的 JavaScript 数据

javascript - 添加超链接到图像(背景图像)

html - 使用 textarea 但不使用输入文本的 CSS 类

javascript - jquery 中 .removeClass() 的参数定义是什么

html - 是否可以在 Notepad++ 中为 2 种语言设置自动完成?

ios - 如何使用 swift 将 google places autocomplete 添加到 xcode(教程)