当光标处于文本框内的光标处时,将文本内容插入到光标处。 相应的js脚本如下: function InsertString(tbid, str){ var tb = document.getElementById(tbid); tb.focus(); if (document.all){ var r = document.selection.createRange(); document.selection.empty(); r.text = str; r.collapse(); r.select(); } else{ var newstart = tb.selectionStart+str.length; tb.value=tb.value.substr(0,tb.selectionStart)+str+tb.value.substring(tb.selectionEnd); tb.selectionStart = newstart; tb.selectionEnd = newstart; } } 全部代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormtest.aspx.cs" Inherits="WebTest1213.WebFormtest" %> <!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"> <mce:script type="text/javascript" ><!-- function InsertString(tbid, str){ var tb = document.getElementById(tbid); tb.focus(); if (document.all){ var r = document.selection.createRange(); document.selection.empty(); r.text = str; r.collapse(); r.select(); } else{ var newstart = tb.selectionStart+str.length; tb.value=tb.value.substr(0,tb.selectionStart)+str+tb.value.substring(tb.selectionEnd); tb.selectionStart = newstart; tb.selectionEnd = newstart; } } // --></mce:script> <div> <asp:Button runat="server" ID="btnJia" Text="+" ToolTip="加号" OnClientClick="InsertString('txtContent','+')"/> <asp:Button runat="server" ID="btnJian" Text="-" ToolTip="减号" OnClientClick="InsertString('txtContent','-')"/> <asp:TextBox runat="server" ID="txtContent" Text="" TextMode="MultiLine" Width="200px" Height="300px"></asp:TextBox> </div> </form> </body> </html>