1

以下は、ドロップダウンを取得し、そこからインライン幅スタイルを取得しようとしている jQuery のスニペットです。私の問題は、Safari IIで 225が得られないことです。newWidth

たとえばr_select、Safari が Firefox とは異なる幅を返す理由がわかりません。

// get the current select box
targetSelect = $(this);
newWidth = parseInt(targetSelect.css('width'));

私のマークアップ:

<select name="r_select" id="r_select" style="width: 225px; height: 50px; float: left;">
    <option>Mickelson</option>
    <option>Montgomerie</option>
    <option>Watson</option>
    <option>Casey</option>
</select>

このドロップダウンで同じ問題が発生していないことを追加する必要があります。

<select id="r_select_overlay" class="r_select_overlay_test no_style" name="r_select_overlay" style="width: 145px; height: 50px; float:left;">
        <option>Mickelson</option>
        <option>Montgomerie</option>
        <option>Watson</option>
        <option>Casey</option>
</select>
4

1 に答える 1

2

単に幅ではなく、outerWidth を取得してみて、それが機能するかどうかを確認してください。

http://api.jquery.com/outerWidth/

于 2012-07-12T09:58:36.370 に答える