将按钮添加到表格JavaScript

时间:2019-05-21 12:38:47

标签: javascript html web

我试图将“下载”按钮添加到表中,但是某些按钮返回null,然后出现此错误:

  

“无法将属性'onclick'设置为null”。

JS代码:

 var table = $('#dataTables-example').DataTable();
 ref.on("value", function(snapshot) {
 snapshot.forEach(function(childSnapshot) {
  var childData = childSnapshot.val();
  var number = childData.ParNumber;
  var numOfTr = childData.NumOfTry;
  var startTime = childData.startTime;
  numberofbutton = Math.random();
  table.row.add( [
      coursrNum,
      number,
      numOfTr,
      startTime,
    '<button id =' +numberofbutton+'>Download File</button>'
  ] ).draw( false );
     var button = document.getElementById(numberofbutton);
     button.onclick = function(){ myScript(number+'_'+numOfTr)};
    });

});

0 个答案:

没有答案