复制代码 代码如下: <BR> function getTxt1CursorPosition(){<BR> var oTxt1 = document.getElementById("txt1");<BR> var cursurPosition=-1;<BR> if(oTxt1.selectionStart){//非IE浏览器<BR> cursurPosition= oTxt1.selectionStart;<BR> }else{//IE<BR> var range = document.selection.createRange();<BR> range.moveStart("character",-oTxt1.value.length);<BR> cursurPosition=range.text.length;<BR> }<BR> alert(cursurPosition);<BR> } <P> function setTxt1CursorPosition(i){<BR> var oTxt1 = document.getElementById("txt2");<BR> var cursurPosition=-1;<BR> if(oTxt1.selectionStart){//非IE浏览器<BR> oTxt1.selectionStart=i;<BR> }else{//IE<BR> var range = oTxt1.createTextRange();<BR> range.move("character",i);<BR> range.select();<BR> }<BR> } <P> function getTa1CursorPosition(){<BR> var evt =window.event?window.event:getTa1CursorPosition.caller.arguments[0];<BR> var oTa1 = document.getElementById("ta1");<BR> var cursurPosition=-1;<BR> if(oTa1.selectionStart){//非IE浏览器<BR> cursurPosition= oTa1.selectionStart;<BR> }else{//IE<BR> var range = oTa1.createTextRange();<BR> range.moveToPoint(evt.x,evt.y);<BR> range.moveStart("character",-oTa1.value.length);<BR> cursurPosition=range.text.length;<BR> }<BR> alert(cursurPosition);<BR> } <P> function setTa1CursorPosition(i){<BR> var oTa2 = document.getElementById("ta2");<BR> if(oTa2.selectionStart){//非IE浏览器<BR> oTa2.selectionStart=i;<BR> oTa2.selectionEnd=i;<BR> }else{//IE<BR> var range = oTa2.createTextRange();<BR> range.move("character",i);<BR> range.select();<BR> }<BR> }<BR>