您需要使用JavaScript这样的:
<!--
Place this script before closing </body> tag so that
DOM (HTML elements tree) is already built when the script is running
-->
<script>
// create a closure to not pollute global scope
!function() {
// cache reference to keyDates element
var keyDates = document.getElementById('key_dates');
// set scroll to the height of one row
keyDates.scrollTop = 150; // substitute `150` with height of one row
}();
<script>
Here是element.scrollTop
的文档
如果您正在使用jQuery,你像这样做(和here是文档);
<script>
$('#key_dates').scrollTop(150);
</script>
使用jQuery的例子:http://jsfiddle.net/gryzzly/CjdwX/
基于高度的调整似乎更适合我,因为我没有真正控制行。但是,当我在jquery $('#key_dates')中添加了这个代码片段时,scrollTop(150);滚动条的位置似乎根本没有改变。我可能在这里错过了什么? – KeenUser
似乎适用于我:http://jsfiddle.net/gryzzly/CjdwX/ –
注意到我们更改了父容器,容器,应用了'overflow:scroll'的元素的'scrollTop' –