http://community.csdn.net/Expert/topic/3211/3211168.xml?temp=.6012995

解决方案 »

  1.   

    <SCRIPT  language=javascript>     
    function moveAtCaret(obj,n)
    {
        //将obj中光标向dirc方向移动n个字符 
        obj.focus(); 
        var rng=document.selection.createRange(); 
        rng.moveStart("character", n); 
        rng.select(); 

    </SCRIPT> 
    <body  onload="moveAtCaret(show,5)">
    <input id="show" value="1234567890">
      

  2.   


    怎样实现这个功能:怎样通过单机按钮 在文本框中的光标位置插入字符??????? 比如   AB|cd
      此时光标在 AB和cd中间,我想单击按钮就在光标处插入字符呢!
      

  3.   

    http://community.csdn.net/Expert/topic/3399/3399799.xml?temp=.5488245
      

  4.   

    <input name=a size=20 value=ABcd>
    <input type=button value="当前光标的位置" onclick="getpos(a)">
    <script type="text/javascript">
    function getpos(obj)
    {
        obj.focus();
        var r = document.selection.createRange();
        var i;
        var s = obj.value;
        r.collapse(false);
        r.setEndPoint("StartToStart", obj.createTextRange());
        i = r.text.length;
        obj.value = s.substr(0,i) + 'p' + s.substr(i,s.length);
    };
    </script>
    插入"p"~~~
      

  5.   

    对于光标位置的移动:
    <textarea id="TxtID" rows=5 cols="80%"></textarea><br/>
    <input type=text id="ReplaceID"><br/>
    <input type=button value="获取选择文本" onclick="TxtID.focus();window.confirm(document.selection.createRange().duplicate().text);">
    <input type=button value="更改选择文本" onclick="TxtID.focus();document.selection.createRange().duplicate().text=ReplaceID.value;">
    <input type=button value="移动光标" onclick="TxtID.focus();document.selection.createRange().moveStart('character',5);">