如何使用js向td添加按钮并设置多个attr?

时间:2017-09-18 17:32:33

标签: javascript firebase

我的代码是这样,但是attr delete botton,not work

var newList = snapshot.val();

var tableList = document.getElementById('mytable'); 
var rowIndex = 1;
var row = tableList.insertRow(rowIndex);

var cellName = row.insertCell(0);
var cellBottonDelete = row.insertCell(1); 

cellName.appendChild(document.createTextNode(newList.name));
cellBottonDelete.appendChild(document.createElement("input", { type: "button", value:"Delete"}));

rowIndex = rowIndex + 1;

输入已创建,但不是attr。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

这是解决方案

var newList = snapshot.val();
var tableList = document.getElementById('mytable'); 
var rowIndex = 1;
var row = tableList.insertRow(rowIndex);
var cellName = row.insertCell(0);
var cellBottonDelete = row.insertCell(1); 

var itd = document.createElement('input');
itd.setAttribute("type","button");
itd.setAttribute("value","Delete");

cellName.appendChild(document.createTextNode(newList.name));
cellBottonDelete.appendChild(itd);

rowIndex = rowIndex + 1;