javascript一行中删除按钮的默认外观

javascript一行中删除按钮的默认外观,javascript,css,html,Javascript,Css,Html,当我单击“插入行”按钮时,我希望“删除”按钮也默认与行一起出现。 比如说 function addRow(demo) { var x=document.getElementById(myTable)' var row=x.insertRow(0); var cell1=row.insertCell(0); var cell2=row.insertCell(1); cell1.innerHTML=demo; cell2.innerHTML=(He

当我单击“插入行”按钮时,我希望“删除”按钮也默认与行一起出现。 比如说

function addRow(demo)
  {
    var x=document.getElementById(myTable)'
    var row=x.insertRow(0);
    var cell1=row.insertCell(0);
    var cell2=row.insertCell(1);
    cell1.innerHTML=demo;
    cell2.innerHTML=(Here I want the delete button to appear);        
  }
当按下每行中已有的删除按钮时,我应该编写什么函数来删除该行

    cell1.innerHTML=demo;
    cell2.innerHTML=(Here I want the delete button to appear);        
}
可更改为:

    cell1.innerHTML=demo;
    var delBtn = document.createElement('input');
    delBtn.setAttribute('type', 'button');
    delBtn.setAttribute('value', 'Delete');
    delBtn.addEventListener('click', nameOfYourDelBtnHandlerFunction, false);
    cell2.appendChild(delBtn);
}
编辑:示例按钮按下处理程序功能

function onRowDeleteBtn()
{
    var pressedButton = this;                   // must attach the handler with addEventListener, otherwise 'this' will not hold the required value
    var parentCell = pressedButton.parentNode;  // get reference to the cell that contains the button
    var parentRow = parentCell.parentNode;      // get ref to the row that holds the cell, that holds the button
    var parentTbody = parentRow.parentNode;     // get ref to the tbody that holds the row, that holds the cell, that holds the button
    parentTbody.removeChild(parentRow);         // nuke the row element
}

只需使用removeattrpossible duplicate of I Not know what is handler function。此实例中的“handler function”是指当按下按钮时将调用的代码,即它处理所需的响应。在您的例子中,您希望在删除按钮之前使用它来获取对保存按钮的行的引用。我将在一两分钟内为我的答案添加一个示例函数。