Firebase Web App:如何在我的innerHTML

时间:2018-12-13 08:36:38

标签: javascript firebase firebase-realtime-database

这是我的代码段

function add() {
    var mesaj = document.getElementById("mess").value;
    var database = firebase.database();
    
        var ref = database.ref("user");
        
        var data = {
            mess: mesaj,
            
        };
        ref.push(data);
        console.log(data);
    };
    
 //Retrieve Data From Firebase
 var ref = firebase.database().ref("user");
 var table = document.getElementsByTagName('table')[0];
 ref.orderByKey().on("child_added", function(child) {

  console.log(child.key+child.val());
  var tr = document.createElement('tr');
  var td = document.createElement('td');
  td.innerText = JSON.stringify(child.val().mess);
  tr.appendChild(td);
  table.appendChild(tr);
});
<table class="table table-striped table-dark">

</table>

<button onclick="add()" type="button" class="fas fa-location-arrow btn btn-success"></button>

我想获取数据并更改“当前用户”的消息背景颜色

像这样= enter image description here

0 个答案:

没有答案