【问题标题】:jQuery Autocomplete - cannot find where the width is being set on the suggestions div?jQuery Autocomplete - 找不到在建议 div 上设置宽度的位置?
【发布时间】:2014-07-22 09:05:15
【问题描述】:

我正在使用 jQuery Autocomplete - 一切正常但是我想修改宽度,目前在 Firebug 中宽度设置为 268px,但我希望这是 520px。

我看不到样式表中宽度设置为 268px 的位置,尝试用 !important 覆盖“自动完成建议”似乎不起作用。

关于如何将此宽度从 268 像素设置为 520 像素的任何想法?

<div id="appendTo">
<div class="autocomplete-suggestions" style="position: absolute; width: 268px; max-height: 300px; z-index: 9999;">

现有的 CSS

.autocomplete-suggestions {
    background-color: #79BE28;
    border-radius: 7px;
    box-shadow: 0 4px 4px #CCCCCC;
    max-height: 650px !important;
    width: 520px !important;
}
.autocomplete-suggestions .autocomplete-suggestion {
    font-size: 12px;
    text-align: left;
    color: #fff;
    padding: 4px 15px;
    cursor: pointer;
}
.autocomplete-suggestions .autocomplete-suggestion:hover {
    font-weight: bold;
}
.autocomplete-suggestions .autocomplete-suggestion strong {
    text-decoration: underline;
}

.autocomplete-suggestion {
    z-index: -1 !important;
}

【问题讨论】:

    标签: javascript jquery css stylesheet client-side


    【解决方案1】:

    您可能会这样做。 (见Changing width of jquery-ui autocomplete widgets individually)

    $('#input').autocomplete({  
       source: mysource,   
       open: function() { $('#autocomplete-suggestions').width(520) }  
    });
    

    【讨论】:

    • 我的原始代码现在似乎可以工作了?!?一定是一些奇怪的浏览器缓存问题,虽然我更喜欢你提供的解决方案,谢谢 Andrew :)
    【解决方案2】:

    因为它被设置为内联 CSS,所以你不能用 CSS 样式表覆盖它。您将不得不使用 js 更改值。在 jQuery 设置后更改或删除此内联 css 值

    在 jquery 自动完成事件期间尝试一下:open( event, ui )

    $( ".autocomplete-suggestions" ).autocomplete({
      open: function( event, ui ) {
    $('.autocomplete-suggestions .your-list-selector').css( 'width', '520px' );
    }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-04-22
      • 1970-01-01
      • 2013-03-05
      • 1970-01-01
      • 2013-03-27
      • 2014-04-21
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多