[ASP.NET]讓TextBox bar隨文字自動下捲

  • 4660
  • 0
  • C#
  • 2011-03-15

[ASP.NET]讓TextBox bar隨文字自動下捲

網友問題

自己練習該效果順便紀錄備忘。

 

.aspx


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
    <script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="text_content" runat="server" TextMode="MultiLine" Rows="5" Columns="15">
    i am rico
    i am rico
    i am rico
    i am rico
    i am rico
    i am rico
    i am rico
    </asp:TextBox><br/>
    </div>
    </form>
</body>
</html>

<script type="text/javascript">
$(function() {        
            window.setInterval("add()",1000); //每一秒重複執行  
        });
        
        function add() {
           var mytext = $("#text_content");      
           $(mytext).append("I am RiCo <br/>");
           scroll(mytext,mytext[0].scrollHeight);//移至特定位置  
        }
 
        function scroll(ctl, ht) {
            $(ctl).scrollTop(ht);   
        }


執行

image   

image