模拟 鼠标下文本的最后一个字符。

解决方案 »

  1.   

    L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
    <input type="text" id="txtInput" value="input something" />
      <script type="text/javascript">
      <!--
    function $(sId)
    {
    return document.getElementById(sId);
    }function setCaretById(sId, iPos)
    {
      var oTextBox = document.getElementById(sId);
    setCaret(oTextBox, iPos);
    }
    function setCaret(oTextBox, iPos)
    {
      var r = oTextBox.createTextRange(); 
      r.collapse(true); 
      r.moveStart('character', iPos); 
      r.select();
    }
    $("txtInput").onblur = function() {
    setCaret(this, this.value.length);
    };
      //-->
      </script>
     </body>
    </html>