简体   繁体   中英

How do I add a button to a td using js and set multiple attr?

My code is this, but 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;

input is created but attr not. Any idea?

It's the solution

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM