如何使用jquery将Select Element width设置为span元素?

时间:2016-05-19 12:07:23

标签: jquery

<td class="ADDDLFFForm2" colspan="5">
    <div>
        <select style="width: 91px; display: none;">
            <span id="" class="selectboxit selectboxit-enabled selectboxit-btn"  style="width: 95px;">
                <span class="selectboxit-option-icon-container" style="width: 95px;">
                    <i id=""></i>
                </span>
                <span id="" class="selectboxit-text" unselectable="on" data-val="1" aria-live="polite" style="max-width: 79px;">
                    Deutsch
                </span>
                <span id="" class="selectboxit-arrow-container" unselectable="on">
                    <i id="" class="selectboxit-arrow selectboxit-default-arrow" unselectable="on"></i>
                </span>
            </span>
            <ul class="selectboxit-options selectboxit-list" tabindex="-1" role="listbox" aria-hidden="true" style="min-width: 109px;">
                <li data-id="0" data-val="1" data-disabled="false" class="selectboxit-option selectboxit-option-first selectboxit-selected" data-icon="/WikiNotificationMails - Copy/Base/Untitled/Image.ashx?" role="option">
                    <a class="selectboxit-option-anchor">
                        <span class="selectboxit-option-icon-container" style="width: 95px;">
                            <i></i>
                        </span>

我想将select元素宽度设置为与span class="selectboxit selectboxit-enabled selectboxit-btn"宽度相同。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

试试这个:

var width = $(".selectboxit-enabled").css("width"); //First get the width of span with class selectboxit-enabled

$("select").css("width",width); // then set that width to select