Recently, a Public Editor function is involved in project development. One function is to insert a string at the cursor of Textbox (textfield or textarea in extjs) in Asp.net. It is difficult to solve the problem at the beginning. Unlike in desktop development, it is easy to get the cursor position and insert characters. I found that some processing functions are also available in Web development. I want to share it with his home.
Insert string functions
Function insertvalue (STR) {var tbformula = document. getelementbyid ("formula"); If (document. selection) {tbformula. focus (); document.exe ccommand ("Paste", 0, STR)} else {var prefix, suffix, start, Len; Len = Str. length; Start = tbformula. selectionstart; prefix = tbformula. value. substring (0, start); suffix = tbformula. value. substring (tbformula. selectionend); tbformula. value = prefix + STR + suffix; tbformula. setselectionrange (start + Len, start + Len);} tbformula. focus ();}