在Safari上返回不一致的jQuery CSS width属性

时间:2012-07-12 09:50:20

标签: jquery html css markup

下面是我的jQuery片段,我抓住一个下拉列表并试图从中获取内联宽度样式。我的问题是,在Safari上,我获得225的newWidth

targetSelect是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>

1 个答案:

答案 0 :(得分:2)

尝试获取outerWidth而不是简单的宽度,看看是否有效。

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

相关问题