<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;
可以在Firefox和IE中的这个DIV中向下滚动吗?
答案 0 :(得分:2)
您的代码有点不对,因为jQuery中的scrollTop
实际上是一个函数,而不是属性。而scrollHeight是一个原生的javascript属性,与jQuery无关。所以你会想做这样的事情:
$('#aaa').scrollTop($("#aaa")[0].scrollHeight);
话虽这么说,你应该把你的div引用缓存在变量中,而不是两次得到它,如下所示:
var $aaa = $('#aaa');
$aaa.scrollTop($aaa[0].scrollHeight);
答案 1 :(得分:0)
$("#aaa").attr({ scrollTop: $("#aaa").attr("scrollHeight") });
将attr
替换为prop
以获取jQuery 1.6 +。