问题描述
感谢您的时间,我计算了< textarea>
的scrollHeight,并在Microsoft上运行它Internet Explorer 8和Firefox。我在上述浏览器中获得了不同的scrollHeight。
我的应用程序中使用的代码
function getScrollHeight(id){
textareaObj = document.getElementById(id);
var scrollH = textareaObj.scrollHeight;
alert(scrollH);
scrollHeight是< textarea> ;
在MSIE8和FF中有所不同?
如果是这样,那么如何实现在提到的浏览器中获得相同的scrollHeight? b
感谢,
-Pravin
解决方案在IE中,scrollHeight计算为元素内容的高度,所以如果内容
较少,不需要滚动条,则会得到一个小于元素高度的值。
在这种情况下,您可以检索offsetHeight而不是scrollHeight。
如果您确实需要它,您还需要计算元素的填充和边框宽度,它在两个浏览器中都有所不同。另外,如果你不自己设置字体大小和行高,那么每个浏览器都会将其设置为默认值。
不管你做什么,在IE访问那些不是在body加载之前的属性已经被解雇了,否则你会得到奇怪的结果。
Thanks for your time,
I have calculated scrollHeight of <textarea>
and run it on Microsoft Internet Explorer 8 and Firefox. I am getting different scrollHeight in above mentioned browsers.
Code used in my application
function getScrollHeight(id) {
textareaObj = document.getElementById(id);
var scrollH = textareaObj.scrollHeight;
alert(scrollH);
}
Is scrollHeight of <textarea>
in MSIE8 and FF differ ?
If so then how to achieve to get same scrollHeight in mentioned browsers?
Thanks,
-Pravin
解决方案 In IE scrollHeight is calculated to the height of the content of the element, so if there is less content that no scrollbars are needed, you will get a value less than the height of the element.
In this case you can retrieve offsetHeight instead of scrollHeight.
If you need it very exact, you furthermore need to calculate with the padding and border-width of the element, it differs in both browsers what all they include to that. Also the font-size and line-height is related if you dont set them on your own, while every browser will take it's defaults.
Whatever you do, in IE access the propertys not before body's onload has fired, otherwise you will get weird results.
scrollHeight @ MSDN
scrollHeight @ MDN
这篇关于< textarea>的scrollHeight在MSIE8和FF中有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!