function AddNew(){
 ...........
 newCell2.firstChild.focus();
}

解决方案 »

  1.   

    增加行以后,你还要让其中的input获得焦点啊,这种改一下啊,加一行: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>";
     newCell2.children[0].focus();
    }
      

  2.   

    为什么在getfocus()这不可以设置呢?
    这个函数错在那里呢?
      

  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>";
    //***************我的加的语句*****************************************************
     newCell2.firstChild.focus();
    //*******************************************************
    }
    function getfocus(){
       event.srcElement.style.background="ffff00";
       event.srcElement.focus();
       event.srcElement.select();
    }</script>
      

  4.   

    新增的可以了,
    能不能在getfocus()里进行为它进行设置焦点呢?因为在function deptUpdate(){
    opFlag = 0;
    var power_id = window.mytable.rows[Count].cells[0].innerHTML;
    var val = window.mytable.rows[Count].cells[1].innerHTML;
    window.mytable.rows[Count].cells[1].innerHTML = "<input type='text' name='power_name'size='50' onfocus='getfocus()' value='"+val+"' onkeyup='upenter2()' onblur='lostfocus2()' size=30  maxlength=50>";
    }不知在这里有怎样进行设置焦点了?
      

  5.   

    我明白了。也不是一样吗?window.mytable.rows[Count].cells[1].firstChild.focus();