Javascript 在Internet Explorer中获取不带填充的元素的宽度

Javascript 在Internet Explorer中获取不带填充的元素的宽度,javascript,mootools,Javascript,Mootools,我希望将网站上的图像与其包含元素的大小相适应,因此我有以下几点: if (userHasMicrositePhoto) { var width = $('micrositePhotoDiv').getComputedSize().width; $('micrositePhoto').src = "flash/userImage.ashx?type=micrositePhoto&id=" + userId + "&width=" + width; } 我的处理程序

我希望将网站上的图像与其包含元素的大小相适应,因此我有以下几点:

if (userHasMicrositePhoto) {
    var width = $('micrositePhotoDiv').getComputedSize().width;
    $('micrositePhoto').src = "flash/userImage.ashx?type=micrositePhoto&id=" + userId + "&width=" + width;
}
我的处理程序文件userImage.ashx返回ID给定的图像,并缩放到作为参数给定的宽度

这在firefox、chrome&co中运行良好,但在Internet explorer中不起作用-返回的图像太大。我认为这是因为
.getComputedSize().width
在Internet explorer中报告了一个宽度,该宽度包括填充的大小(但在边框或边距上),但在其他浏览器中仅返回可用区域。因此,internet explorer提供的宽度太大

我找不到任何其他可用于
.getComputedSize()
的字段,这些字段允许我在Internet Explorer中查找“实际”宽度。我尝试使用
.getComputedStyle()
获取填充,以便从总宽度中减去它,但这会返回一个字符串,我将
micrositePhotoDiv
元素的样式设置为
填充:0.75em
,因此这不起作用


要在internet explorer中获得正确的宽度,我需要做什么?

您可以将填充设置为0,但检查计算样式的大小和位置通常是有问题的,并且很难协调ACREOS浏览器

在所有浏览器上改用offsetWidth或clientWidth。

jQuery就是这样做的(请参阅)

正如您所看到的,通常
getComputedStyle
返回以像素为单位的宽度,因此您通常可以这样做(旧IE除外):


我真的不能为这个元素设置任何填充,offsetWidth和clientWidth在firefox和IE中都报告了错误(更大)的大小。没有办法解决这个问题吗?“这些不是你想要的答案”仍然..这个谜题没有答案。
var width = parseFloat(window.getComputedStyle(elem).width);