Dieser Artikel beschreibt die Implementierungsmethode zur Aufzeichnung der Cursorposition im Editor von JavaScript. Teilen Sie es für Ihre Referenz wie folgt weiter:
<! DocType html public "-// w3c // dtd xhtml 1.0 strict // en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Unt titled document</title></head><body><script type="text/javascript">function $(ele){return document.getElementById (ele)} // Ort im Datensatzeditor var selection_start; var selection_end; Funktion SavePos (TextBox) {var start = 0; var end = 0; if (typeof (textBox.selectionStart) == "Nummer") {// nicht ie //alert(TypeOf(TextBox.SelectionStart)); start = textBox.SelectionStart; End = textBox.SelectionEnd; } else if (document.Selection) {var range = document.Selection.Createrange (); if (Bereich.Parentelement (). id == textBox.id) {var range_all = document.body.createTextrange (); range_all.movetoelementText (textBox); für (start = 0; range_all.comPareendpoints ("startTostart", range) <0; start ++) range_all.movestart ('Zeichen', 1); für (var i = 0; i <= start; i ++) {if (textbox.value.charat (i) == '/n') start ++; } var range_all = document.body.createTextrange (); range_all.movetoelementText (textBox); für (end = 0; range_all.comPareendpoints ('startToend', range) <0; end ++) range_all.movestart ('Zeichen', 1); für (var i = 0; i <= end; i ++) {if (textbox.value.charat (i) == '/n') End ++; }}} selection_start = start; Selection_end = Ende; } </script> <form action = "" id = "test"> <textarea id = "t" onfocus = "SavePos (this); onmouseUp = "Savepos (this); $ ('log'). value = selection_start"> </textarea> <Eingabe type = "text" id = "log"/> </form> </body> </html>For more information about JavaScript, please check the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript Traversalalgorithmen und -techniken "und" Zusammenfassung der Nutzung von JavaScript -Mathematischen Operationen "
Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.