代码改变世界

设置多行 TextBox 滚动条位置

2009-02-20 13:20  晓风残月  阅读(3321)  评论(0编辑  收藏  举报
多行 TextBox 刷新后默认回到首行,通过设置 txt.scrollTop = txt.scrollHeight 强制滚动尾行:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title></title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    http://topic.csdn.net/u/20090220/10/92760759-6e9c-4cf2-8660-c2fb5cf004f0.html?seed=1331838345
        
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Rows="10" Columns="10">
    * 移动开发者自己的聚集地
    * 『送』千元开发板,嵌入式开发热招!
    * 构建出色多核应用程序
    * CSDN网友快速赚分技巧
    * IBM dW精华技术,开发者必看
    * 走进嵌入式学院,就业世界500强
    * 财富两千强公司都选甲骨文SOA解决方案
    * CUDA—大规模并行计算的利器
        
</asp:TextBox>        
        
<script type="text/javascript">
            window.onload 
= function() {
                
var txt = document.getElementById("TextBox1");
                document.body.focus();
                txt.scrollTop 
= txt.scrollHeight;        // IE, FF                
                //txt.focus(); // FF#OK, IE#Resume to Top
            }
        
</script>
    
</div>
    
</form>
</body>
</html>