在Textrange中怎么取得光标所在的当前位置

在Textrange中怎么取得光标所在的当前位置。
也可以说在IFRAMEh中。
---------------------------------------------------------------

http://51js.1000box.net/showmsg.php?bo=3&msgid=40251
---------------------------------------------------------------

1<input id="txt1" value="0123456789"/>
1<input onclick="getCaretPos(txt1)" type="button" value="get caret position"/>
 1<script language="javascript">   
 2function getCaretPos(obj){   
 3obj.focus();   
 4var workRange=document.selection.createRange();   
 5var allRange=obj.createTextRange();   
 6workRange.setEndPoint("StartToStart",allRange);   
 7len=workRange.text.length;   
 8if (len >= obj.value.length)   
 9alert("at the end");   
10else if (len == 0)   
11alert("at the start");   
12else   
13alert("in the middle");   
14}   
15</script>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus