Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function getTxt1CursorPosition (){
Var oTxt1 = document. getElementById ("txt1 ");
Var cursurPosition =-1;
If (oTxt1.selectionStart) {// non-IE browser
CursurPosition = oTxt1.selectionStart;
} Else {// IE
Var range = document. selection. createRange ();
Range. moveStart ("character",-oTxt1.value. length );
CursurPosition = range. text. length;
}
Alert (cursurPosition );
}
Function setTxt1CursorPosition (I ){
Var oTxt1 = document. getElementById ("txt2 ");
Var cursurPosition =-1;
If (oTxt1.selectionStart) {// non-IE browser
OTxt1.selectionStart = I;
} Else {// IE
Var range = oTxt1.createTextRange ();
Range. move ("character", I );
Range. select ();
}
}
Function getTa1CursorPosition (){
Var evt = window. event? Window. event: getTa1CursorPosition. caller. arguments [0];
Var oTa1 = document. getElementById ("ta1 ");
Var cursurPosition =-1;
If (oTa1.selectionStart) {// non-IE browser
CursurPosition = oTa1.selectionStart;
} Else {// IE
Var range = oTa1.createTextRange ();
Range. moveToPoint (evt. x, evt. y );
Range. moveStart ("character",-oTa1.value. length );
CursurPosition = range. text. length;
}
Alert (cursurPosition );
}
Function setTa1CursorPosition (I ){
Var oTa2 = document. getElementById ("ta2 ");
If (oTa2.selectionStart) {// non-IE browser
OTa2.selectionStart = I;
OTa2.selectionEnd = I;
} Else {// IE
Var range = oTa2.createTextRange ();
Range. move ("character", I );
Range. select ();
}
}
</Script>