<div id="aaa">sdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdfsdfas fasdfa asdf </div>
#aaa {
height: 100px;
width: 200px;
overflow: scroll;
}
$("#aaa").scrollTop = $("#aaa").scrollHeight;
http://jsfiddle.net/PfA7Q/2/
是否可以在Firefox和IE中在此DIV中向下滚动?
最佳答案
您的代码有点错误,因为jQuery中的scrollTop
实际上是一个函数,而不是属性。 scrollHeight是一个原生javascript属性,与jQuery不相关。因此,您需要执行以下操作:
$('#aaa').scrollTop($("#aaa")[0].scrollHeight);
http://jsfiddle.net/PfA7Q/14/
话虽这么说,您应该将div引用缓存在一个变量中,而不是两次获取它,如下所示:
var $aaa = $('#aaa');
$aaa.scrollTop($aaa[0].scrollHeight);