您需要使用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' –