[英]javascript style.width not working in firefox with transitional doctype
我有一个脚本,可以为页面上弹出的小 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;
在 IE 和没有 DOCTYPE 的 FF 中,第一个警告说 0,第二个警告说 320(这是代码中其他地方设置的宽度)
在 FF 中,DOCTYPE 为 XHTML/Transitional,两个警报都显示 0。知道这里发生了什么吗? 我想我可能需要在 Transitional 中明确设置 DIV 的位置,但我不确定。
你试过设置:
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
我发现尝试设置数字的宽度/高度,没有单位可能会导致问题。
您可以使用:
document.getElementById("td").style.visibility="hidden";
document.getElementById("td").style.display="none";
而不是宽度属性。
有用!
在CSS中使用.important会覆盖上面的JavaScript,宽度不会改变。 IE。
宽度:16.5%;重要;
应该变成:
宽度:16.5%;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.