本文介绍了强制滚动< div>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在div中显示HTML文本,并打开页面滚动到底部的
。 (我的div有溢出:自动,所以它出现滚动条)


我发现这适用于textarea:


文件.all.MyDivId.scrollTop = document.all.MyDivId] .scrollHeight;


但这对div不起作用。我正在使用div,因为我显示的文本包含HTML。当然可以简单地设置一个滚动条

到div的底部???谢谢!

解决方案




是的,可能。


-

兰迪

comp.lang.javascript常见问题 -





它也不适用于任何不支持微软的b $ b专有文档的浏览器。所有。


为什么锚不会工作?


-

Rob




试试这个...


< script type =" text / javascript">


函数scrollDiv()

{

var el;

if((el = document.getElementById (''MyDivId''))

&&(''undefined''!= typeof el.scrollTop))

{

el.scrollTop = 0;

el.scrollTop = 5000;

}

}


window.onload = scrollDiv;


< / script>


I want to display HTML text inside a div and have the page open scrolled to
the bottom. (My div has overflow:auto so that it appears with scroll bars)

I have found this that works on a textarea:

document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;

But this doesn''t work on a div. I am using a div because the text I am
displaying contains HTML. Surely it is possible to simply set a scroll bar
to the bottom in a div??? Thanks!

解决方案



Yep, its possible.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq




Nor will it work in any browser that doesn''t support Microsoft''s
proprietary document.all.

Why wont an anchor work?

--
Rob




Try this...

<script type="text/javascript">

function scrollDiv()
{
var el;
if ((el = document.getElementById(''MyDivId''))
&& (''undefined'' != typeof el.scrollTop))
{
el.scrollTop = 0;
el.scrollTop = 5000;
}
}

window.onload = scrollDiv;

</script>


这篇关于强制滚动&lt; div&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:30