Inserts the content at the cursor.

Source: Internet
Author: User

function Insertatcursor (MyField, myvalue) {
if (document.selection) {//ie
Myfield.focus ();
var sel = Document.selection.createRange (); Create Range Object
Sel.text = myvalue; Since the length of the Range object we select is the cursor, the insertion value can be directly assigned
}else if (Myfield.selectionstart | | myfield.selectionstart = = ' 0 ') {
var startpos = Myfield.selectionstart; The beginning of the cursor
var endpos = myfield.selectionend; End of cursor

Refactor value, the value taken from the starting point of the cursor plus the value inserted at the cursor and the intercept value equal to the new value at the end of the cursor to the end of the value

Myfield.value = myField.value.substring (0, startpos) + myvalue + myField.value.substring (endpos, MyField.value.length) ;
}
}

Inserts the content at the cursor.

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.