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

解决方案 »

  1.   

    <input value=0123456789 id="txt1">
    <input type="button" value="get caret position" onclick="getCaretPos(txt1)">
    <script language="javascript">
    function getCaretPos(obj){
     obj.focus();
     var workRange=document.selection.createRange();
     var allRange=obj.createTextRange();
     workRange.setEndPoint("StartToStart",allRange);
     len=workRange.text.length;
     if (len >= obj.value.length)
      alert("at the end");
     else if (len == 0)
      alert("at the start");
     else
      alert("in the middle");
    }
    </script>