简体   繁体   English

选择框不会调整大小

[英]select box won't resize

I have an issue where I have a dropdown box that is as wide as the words "choose please" but when I append to the box it adds the new options to the dropdown but is stays the same width even though the new option are much wider. 我有一个问题,我有一个下拉框与“请选择”一样宽,但是当我将其附加到框时,它会将新选项添加​​到下拉框中,但是即使新选项宽得多,它的宽度也保持不变。 How do I force it to update the width. 我如何强迫它更新宽度。

 var sOption = '
<option value="volvo">Volvoooooooooooooooooooooooooooooooooooo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>';

$("mySelect").append(sOption); // how do I force the width to update

This sounds like you have some css forcing the width thinner I would start with 这听起来像您有一些css迫使我开始时要变窄

.mySelect{width:auto;}

and go from there 然后从那里去

This issue is CSS-relative. 此问题是CSS相对的。 By default, it works well: http://jsfiddle.net/featalion/A6qbd/ . 默认情况下,它运行良好: http : //jsfiddle.net/featalion/A6qbd/ So, try to update your width style to automatic resize the select: http://jsfiddle.net/featalion/f5QWH/1/ . 因此,尝试更新您的宽度样式以自动调整选择的大小: http : //jsfiddle.net/featalion/f5QWH/1/

$('#my_select').css('width', 'auto');

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

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