URL: https://www.overclockers.at/coding-stuff/javascripttextarea_voriges_zeichen_selektieren_153304/page_1 - zur Vollversion wechseln!
hallo!
habe ein problem:
ich möchte mittels javascript das vorhergehende zeichen in einer textarea (vor der aktuellen curser position) selektieren, sodass ich es mittels document.selection.createRange() auswählen kann und dann löschen.
jedoch hab ich keine möglichkeit gefunden das zu realisieren!
wisst ihr mehr?
lg
google "javascript textarea get cursor position, 4. Link http://www.faqts.com/knowledge_base....phtml?aid=5967
Code://This function returns the index of the cursor location in //the value of the input text element //It is important to make sure that the sWeirdString variable contains //a set of characters that will not be encountered normally in your //text function getCursorPos(textElement) { //save off the current value to restore it later, var sOldText = textElement.value; //create a range object and save off it's text var objRange = document.selection.createRange(); var sOldRange = objRange.text; //set this string to a small string that will not normally be encountered var sWeirdString = '#%~'; //insert the weirdstring where the cursor is at objRange.text = sOldRange + sWeirdString; objRange.moveStart ('character', (0 - sOldRange.length - sWeirdString.length)); //save off the new string with the weirdstring in it var sNewText = textElement.value; //set the actual text value back to how it was objRange.text = sOldRange; //look through the new string we saved off and find the location of //the weirdstring that was inserted and return that value for (i=0; i <= sNewText.length; i++) { var sTemp = sNewText.substring(i, i + sWeirdString.length); if (sTemp == sWeirdString) { var cursorPos = (i - sOldRange.length); return cursorPos; } } }
danke für den tip
werde ich am montag in der arbeit mal probiern! habe glaub ich einen halben tag gesucht ohne eine lösung zu finden. das problem ist, dass ich ein softkeyboard implementieren muss, jedoch der textarea "backspace" nicht senden kann.
aber wie gesagt, danke nochmal und ich werds auf diese weise versuchen
danke es geht, kann jetzt ein zeichen vor der cursorposition löschen!
habe mir die funktion etwas umgebaut!
Ja, welche genau? Kurze Beschreibung wie, damit andere auch profitieren, waere super. lG
bin am mittwoch wieder in der arbeit, da werd ichs reinstellen!
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025