Use the JS control button time to add the specified content to the text field cursor location.

Source: Internet
Author: User

<pre class= "javascript" name= "code" >
var fm = document.getelementsbytagname (' form ') [0];
var button = document.getelementsbyname ("button");
Gets the value of a cookie function GetCookie (index) {var allcookies = Document.cookie;  var cookie_pos = allcookies.indexof (index), if (cookie_pos! =-1) {Cookie_pos + = index.length + 1;var cookie_end = Allcookie S.indexof (";", Cookie_pos); if (cookie_end = =-1) {    cookie_end = allcookies.length;  }  var value = unescape (allcookies.substring (Cookie_pos, cookie_end)); }    return value;  Gets the cursor position in the text function getcursortposition (ctrl) {var Caretpos = 0;//IE supportif (document.selection) {ctrl.focus (); var Sel = Document.selection.createRange (); Sel.movestart (' character ',-ctrl.value.length); Caretpos = Sel.text.length;} else if (Ctrl.selectionstart | | ctrl.selectionstart = = ' 0 ') Caretpos = Ctrl.selectionstart;return (Caretpos);}

Gets the position of the text cursor and sets a cookie to store the position of the cursor at any point in the variable var textpos = 0;textcontent.onclick  = function () {Textpos = Getcursortposition (textcontent);d ocument.cookie= "textpos=" +textpos;textpos = GetCookie ("Textpos");} Write function of the string content (string) {s = textcontent.value;fm.content.value  = s.substring (0,getcookie ("Textpos") ) +string+s.substring (GetCookie ("Textpos"));}
<pre class= "php" name= "code" >//click the button to add content to the cursor at the text field in the form Button[0].onclick  = function () {content (' [b][/b] ');}

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.