In Asp.net development, a string is inserted at the cursor specified by textbox.

Source: Internet
Author: User

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 ();}

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.