function check_onfocus() 

var e = event.srcElement; 
var r =e.createTextRange(); 
r.moveStart('character',e.value.length); 
r.collapse(true); 
r.select(); 

我已经测试,这个可以的,注意要在所有的文本框中加事件
onfocus='check_onfocus();'

解决方案 »

  1.   

    我看错了楼主的意思,不好意思
    楼主的程序不全,看看下面这个
    <script>
    function getfocus(){       
       window.event.srcElement.style.background="ffff00";
       window.event.srcElement.focus();
       event.srcElement.select();
     }
     </script>
    <input type='text' name='power_name'size='100' onfocus='getfocus()'  size=30  maxlength=50>
    已经经过测试,可以改变背景颜色的
      

  2.   

    不可以,
    当增加时,text还是没有改变颜色和设置焦点。
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="mytable">
      <tr> 
        <td width="18%"><div align="center"><a href="#" onClick="AddNew()">新增</a></div></td>
        <td width="82%">&nbsp;</td>
      </tr>
      <tr bgcolor="#FF0000"> 
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></body>
    </html>
    <script language="JavaScript">
    function AddNew(){
    var tr = mytable.insertRow(mytable.rows.length);
         newCell1 = tr.insertCell(0);
     newCell1.innerText="自动编号";
     newCell2 = tr.insertCell(1);
     newCell2.innerHTML="<input type='text' name='power_name'size='100' onFocus='getfocus()'  size=30  maxlength=50>";
    }
    function getfocus(){
      window.event.srcElement.style.background="ffff00";
       window.event.srcElement.focus();
       event.srcElement.select();
    }</script>当按"新增"后text马上设置焦点和改变颜色。为什么这样不行呢?
      

  4.   

    function AddNew(){
    var tr = mytable.insertRow(mytable.rows.length);
         newCell1 = tr.insertCell(0);
     newCell1.innerText="自动编号";
     newCell2 = tr.insertCell(1);
     newCell2.innerHTML="<input type='text' name='power_name'size='100' onfocus='getfocus(this)'  size=30  maxlength=50>";
    }
    function getfocus(src){       
       src.bgcolor="#ffff00";
       //src.focus();
       src.select();
     }
      

  5.   

    还是不可以。
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="mytable">
      <tr> 
        <td width="18%"><div align="center"><a href="#" onClick="AddNew()">新增</a></div></td>
        <td width="82%">&nbsp;</td>
      </tr>
      <tr bgcolor="#FF0000"> 
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table></body>
    </html>
    <script language="JavaScript">
    function AddNew(){
    var tr = mytable.insertRow(mytable.rows.length);
         newCell1 = tr.insertCell(0);
     newCell1.innerText="自动编号";
     newCell2 = tr.insertCell(1);
     newCell2.innerHTML="<input type='text' name='power_name'size='100' onFocus='getfocus()'  size=30  maxlength=50>";
    }
    function getfocus(){
      window.event.srcElement.style.background="ffff00";
       window.event.srcElement.focus();
       event.srcElement.select();
    }</script>当按"新增"后text马上设置焦点和改变颜色。为什么这样不行呢?