jquery - JavaScript, add in string to text area based on cursor position -
I currently have a system that works like a user when hit hits, so I & lt; Br / & gt;
to add.
The way it works now is to capture the current content of the texture, attach it & lt; Br / & gt;
outputs it and then a whole lot, then it works, but at the end of the content & lt; Br / & gt; Adds
.
$ ("# postcontent"). Keypress (function) {// If entered key entered (eg == 13) {var current HTML = document.gate elementBiID ("poststrain") value; Var current html = current html + "\ n
" Document.getElementById ("Post-content"). Value = currentHTML;}}); The above action's
I know that the current solution is & lt; Br / & gt;
will not work to add to the tag.
I was thinking something like this, but not to make sure how to handle it.
$ ("# postcontent"). Keypress (function (e) {// If the Enter key is pressed (E. == 13) {// Find the position of the cursor // Hold all the contents before the cursor and store it in the var content // First cursor Hold all the contents after and store in different contentApricade document.GetElementById ("postcontent"). Price = Before content + "
Content + Next;} }); Definitely if I am going through it completely, please do not hesitate to provide alternate solutions or help me work on some parts of the phony code. ?
Here's the way jQuery:
$ (document). Ready (function () {$ ("# post content"). Keypress (function (e) {if (e.j == 13) {// var current HTML = document.getElementById ("postcontent") value; / / Var Current HTML = Current HTML + "\ n & lt ('SelectStart'), v = $ ('' '' '' '' '' #postcontent ''). Val (), textBefore = v.substring ( 0, cursorpos), textAfter = v.substring (cursorpage, v.length); $ ('# postcontent'). Val (before text + "
" + text end);}}}; });
Comments
Post a Comment