我必须修复没有“px 或 %”的行内样式的宽度。 无法修改页面中的html和css,只能修改脚本 我想读取宽度(仅使用 javascript)来修复缺少的单位测量值。
问题仅出现在 IE 9 上。在 chrome、FF、safari 中,我可以使用下面的代码调整宽度。
使用 JQuery 1.8.2
/*script in head */
$(function() {
var style = $("#test").attr("style");
alert(style);
//in IE it prints only color:red;border:1px solid red;
});
/* html in body */
<div id="test" style="width:20;color:red;border:1px solid red;">
Content ...
</div>
tis 问题(IE 问题)的一个例子-> http://jsfiddle.net/2QJ96/1/
最佳答案
你可以通过读取宽度
$('#test').css('width');
此外,您的 HTML 需要修改:
/* html in body */
<div id="test" style="width:20px; color:red; border:1px solid red;">
Content ...
</div>
关于jquery - 修复IE中不写 'px or %'的行内样式的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12747148/