javascript style.width无法在firefox中使用过渡doctype

ner*_*lly 7 javascript css doctype transitional

我有一个脚本,可以在页面上弹出一个小DIV.它在IE中都可以正常工作,如果我删除了DOCTYPE,那么在FF中,但是当DOCTYPE是XHTML/Transitional时,在Firefox中,宽度不会改变.

this.container.style.visibility = "visible";
alert("this.container.style.width before = " + this.container.style.width)
this.container.style.width = this.width;
alert("this.container.style.width after = " + this.container.style.width); 
this.container.style.height = this.height;
Run Code Online (Sandbox Code Playgroud)

在IE中,在没有DOCTYPE的FF中,第一个警报显示0,第二个警告显示320(这是代码中其他地方设置的宽度)

在FF中,使用DOCTYPE到XHTML/Transitional,两个警报都显示为0.任何想法在这里发生了什么?我想我可能需要在Transitional中明确设置DIV的位置,但我不确定.

scu*_*ffe 17

你试过设置:

this.container.style.visibility = "visible";
alert("this.container.style.width before = " + this.container.style.width);
this.container.style.width = this.width + 'px';
alert("this.container.style.width after = " + this.container.style.width);
this.container.style.height = this.height + 'px';

//Note the 'px' above
Run Code Online (Sandbox Code Playgroud)

我发现尝试设置数字的宽度/高度,没有单位可能会导致问题.