很简单的<!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> <title></title> <script type="text/JavaScript"> <!-- function scall(){ var textBox = document.getElementById("<%=TextBox1.ClientID%>") textBox.scrollTop = textBox.scrollHeight }function Button1_onclick() { scall() }function Button2_onclick() { var textBox = document.getElementById("<%=TextBox1.ClientID%>") textBox.value += "new Value\r\n" scall() } window.onload=scall //--> </script></head> <body> <form runat="server"> <asp:TextBox ID="TextBox1" runat="server" Columns="50" Rows="6" TextMode="MultiLine"> a b c d e f g h i j k l m n
/// <summary>
/// 浏览器滚动条总在下面
/// </summary>
public static void AlwaysDown()
{
StringBuilder winner = new StringBuilder();
winner.Append("<SCRIPT LANGUAGE=\"javascript1.1\">\n");
winner.Append("<!--\n");
winner.Append("\tvar autoScrollOn = 1;var scrollOnFunction;var scrollOffFunction;\n");
winner.Append("function scrollit()\n\t\t{if(!parent.d.document.inputform.as.checked){autoScrollOn=0;return true;}else {autoScrollOn=1;StartUp();return true;}}\n"); winner.Append("function scrollWindow()\n\t\t{if ( autoScrollOn == 1 ){this.scroll(0, 65000);setTimeout('scrollWindow()',50);}}");
winner.Append("function scrollOn()\n\t\t{autoScrollOn=1;\nscrollWindow();\n}");
winner.Append("function scrollOff()\n\t\t{autoScrollOn=0;}");
winner.Append("function StartUp()\n\t\t{this.onblur=scrollOnFunction;this.onfocus = scrollOffFunction;scrollWindow();}");
winner.Append("\tscrollOnFunction = new Function('scrollOn()')\n");
winner.Append("\tscrollOffFunction = new Function('scrollOff()')\n");
winner.Append("\t\tStartUp();\n");
winner.Append("\n//--></script> "); HttpContext.Current.Response.Write(winner.ToString());
}
#endregion
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title> <script type="text/JavaScript">
<!--
function scall(){
var textBox = document.getElementById("<%=TextBox1.ClientID%>")
textBox.scrollTop = textBox.scrollHeight
}function Button1_onclick() {
scall()
}function Button2_onclick() {
var textBox = document.getElementById("<%=TextBox1.ClientID%>")
textBox.value += "new Value\r\n"
scall()
}
window.onload=scall //-->
</script></head>
<body>
<form runat="server">
<asp:TextBox ID="TextBox1" runat="server" Columns="50" Rows="6" TextMode="MultiLine">
a
b
c
d
e
f
g
h
i
j
k
l
m
n
</asp:TextBox>
<br />
<input id="Button1" type="button" value="修改" onclick="return Button1_onclick()" />
<input id="Button2" type="button" value="添加内容 " onclick="return Button2_onclick()" />
</form>
</body>
</html>