This example describes how to use JavaScript to control and get a text box/text field of the mouse cursor position, the following code compatible with IE and chrome,firefox, we refer to the use of the bar
The code is as follows: <script type= "Text/javascript" > function gettxt1cursorposition () { & nbsp var oTxt1 = document.getElementById ("Txt1"); var cursurposition=-1; if (Otxt1.selectionstart) {/Non IE browser &NBS P cursurposition= Otxt1.selectionstart; }else{//ie var range = d Ocument.selection.createRange (); Range.movestart ("character",-otxt1.value.length); cursurposition=range.text.length; alert (cursurposition); } function settxt1cursorposition (i) { &nbsP var oTxt1 = document.getElementById ("Txt2"); var cursurposition=-1; if (Otxt1.selectionstart) {/Non IE browser &NBS P Otxt1.selectionstart=i; }else{//ie var range = O Txt1.createtextrange (); Range.move ("character", I); range.select (); { function Gett A1cursorposition () { var evt =window.event?window.event: Getta1cursorposition.caller.arguments[0]; var oTa1 = document.getElementById ("ta1"); var CursurposiTion=-1; if (Ota1.selectionstart) {/Non IE browser &NBSP ; cursurposition= Ota1.selectionstart; }else{//ie var range = O Ta1.createtextrange (); Range.movetopoint (EVT.X,EVT.Y); Range.movestart ("character",-ota1.value.length); cursurposition=range.text.length; alert (cursurposition); } function setta1cursorposition (i) { &N Bsp var oTa2 = document.getElementById ("Ta2"); if (Ota2.selectionstart) {/Non IE browser ota2.selectionstart=i; ota2.selectionend=i; }else{//ie var range = O Ta2.createtextrange (); Range.move ("character", I); range.select (); { } </script>