Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
Function Button4_onclick (obj ){
Obj. focus ();
Var rng = document. selection. createRange ();
Rng. setEndPoint ("StartToStart", obj. createTextRange ());
Var eng = document. selection. createRange ();
Eng. setEndPoint ("EndToEnd", obj. createTextRange ());
Var kone = document. getElementByIdx ("Text1 ");
Kone. value = rng. text + "insert character" + eng. text;
}
</Script>
<Input id = "Text1" type = "text" value = "1235467890"/>
<Input id = "Button4" type = "button"
Value = "button" onclick = "return Button4_onclick (Text1)"/>
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" AspCompat = "true" CodeBehind = "WebForm1.aspx. cs"
Inherits = "SJLERP. WebForm1" %>
<! 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">
<Script type = "text/javascript">
Function setCaret (textObj ){
If (textObj. createTextRange ){
TextObj. caretPos = document. selection. createRange (). duplicate ();
}
}
Function insertAtCaret (textObj, textFeildValue ){
If (document. all ){
If (textObj. createTextRange & textObj. caretPos ){
Var caretPos = textObj. caretPos;
CaretPos. text = caretPos. text. charAt (caretPos. text. length-1) = ''? TextFeildValue + '': textFeildValue;
} Else {
TextObj. value = textFeildValue;
}
} Else {
If (textObj. setSelectionRange ){
Var rangeStart = textObj. selectionStart;
Var rangeEnd = textObj. selectionEnd;
Var tempStr1 = textObj. value. substring (0, rangeStart );
Var tempStr2 = textObj. value. substring (rangeEnd );
TextObj. value = tempStr1 + textFeildValue + tempStr2;
} Else {
Alert ("This version of Mozilla based browser does not support setSelectionRange ");
}
}
}
</Script>
<Form id = "form1" action = "" onsubmit = "" method = "post" enctype = "text/plain">
<P>
<Textarea name = "tarea" rows = "" cols = "" style = "width: 300px; height: 120px ;"
Onselect = "setCaret (this );"
Onclick = "setCaret (this );"
Onkeyup = "setCaret (this);"> example: Forget Never subexample: asp.net </textarea>
<Br/>
<Input type = "text" name = "textfield" style = "width: 220px;" value = "insert FireFox"/>
<Br/>
<Input type = "button" value = "insert"
Onclick = "insertAtCaret(this.form.tar ea, this. form. textfield. value);"/>
</P>
</Form>
</Html>