function InsertRow(id)
        {
            
            var   thisRow   =   event.srcElement.parentNode.parentNode;
var   nextRow   =   thisRow.nextSibling;
if (typeof(thisRow.flag)=="undefined" || !thisRow.flag) {
var   tr = table2.insertRow(thisRow.rowIndex + 1); 
var   td = tr.insertCell();
td.colSpan = 5;   
var str  =   Proj.Table_Pass.GetDetail(id).value;  
td.innerHTML = str;
thisRow.flag = true;
} else {
table2.deleteRow(thisRow.rowIndex + 1);
thisRow.flag = false;
}
        }<table class="list" id="table2" cellSpacing="1" width="100%" align="left" border="0">
    <tr>
<td width="30%" align="left" valign="middle">
<a href="#" onclick="InsertRow('130000');">河北省</a>
</td>
    </tr>
</table>这个代码能运行 但是有时候添加的行却在"河北省"这行的上面 请问这是怎么回事?谢谢

解决方案 »

  1.   

    var  tr = table2.insertRow(thisRow.rowIndex + 1); 
    楼主的这句话有些问题,因为insertRow函数如果给出参数1的话就是在现有行的最后追加新行。
    楼主可以试试这个语句看看:
    var  tr = table2.insertRow(1); 
      

  2.   

    var  tr = table2.insertRow(1); 
    这个不行 
    我想在现有行(点击的这行)下面添加一行 所以代码应该是这样 但是就是不明白为什么有时候会跑到最上面去 好像是在第一行上面添加的一个新行 这是为什么呢?