oElement = object.insertBefore(oNewNode [, oChildNode])ExampleThe following example shows how to use the insertBefore method to insert a new item into an existing list.HideExample<SCRIPT>
function insertElement()
{
var nod=document.createElement("LI");
oUL1.insertBefore(nod, oLIYellow);
nod.innerText="Orange";
}
</SCRIPT>
</HEAD>
<BODY>
<SPAN onclick=insertElement()>Click <B>HERE</B> to add an item to the following list.</SPAN>
<UL id="oUL1">
<LI id="oLIRed">Red</LI>
<LI id="oLIYellow">Yellow</LI>
<LI id="oLIBlue">Blue</LI>
</UL>
</BODY>

解决方案 »

  1.   

    Creates a new row (tr) in the table, and adds the row to the rows collection. SyntaxoTR = object.insertRow( [iIndex])
    ParametersiIndex Optional. Integer that specifies where to insert the row in the rows collection. The default value is -1, which appends the new row to the end of the rows collection. Return ValueReturns the tr element object if successful, or null otherwise. 
      

  2.   

    function add()中的 var tr =t1.insertRow();
    改为:var c = document.getElementsByName('tt');
    var j = c.length;
    for(var i=0; i<c.length; i++){
    if(c[i].checked)
    j=i;
    }
    var tr =t1.insertRow(j);
      

  3.   

    if (document.all.YourTableId.rows.length <= 20)
    {
        // Add new row
    }
    else
    {
        alert("Stop, ha");
    }
      

  4.   

    非常感谢你提供的答案,我还有一个问题想问一下大家的!tr.insertCell(1).innerHTML = '<center><input name="model" class="selBoxText" id="model" size="15" onFocus=\"waterEnter(this,\'\');eventRelation(this,\'UpLoadFile1_ShowTags\');\"></center>';
     触发onFocus  事件事,没反应了,无法触发事件! 因为,添加了多行,表单input的的名字都是一样,可能是这个原因吧!   请教一下应该怎么样去解决这个问题
      

  5.   

    id后面跟上i之类的数字作控制。
    楼主先结贴吧,问题越问越多,早都超出20分的范围了。
    ^_^
      

  6.   

    http://blog.csdn.net/rjzou2006/archive/2007/05/15/1610408.aspx