本帖最后由 michael_1981 于 2009-10-24 23:33:58 编辑

解决方案 »

  1.   

    document.activeElement表示窗体活动元素 可以根据光标移到位置设置焦点
      

  2.   

    声明:这种设置只适用于ie,至于ff和chrome,我至今没有找到方法,希望高手作答。
    我这里用的文本框,因为层没有onfocus事件。<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script language="javascript">
    function cc(evt)

    //alert("进来了");
       evt = window.event?window.event:evt;
      var e=evt.srcElement||evt.target;
      var r=e.createTextRange();
      r.moveStart("character",e.value.length/2);
      r.collapse(true);
      r.select();
    }
    </script>
    </head>
    <body>
    <input type="text" id="in" onfocus="cc(event)" />
    <input type="button" value="文本框获得焦点"  />
    </body>
    </html>