[英]How do I add data into html table using jquery?
I'm trying to add data from my firebase realtime database into a html table using jquery and javascript. 我正在尝试使用jquery和javascript将我的firebase实时数据库中的数据添加到html表中。 I'm new to jquery, so I more or less have no idea what I'm doing. 我是jquery的新手,所以我或多或少都不知道我在做什么。 I can retrieve the data but I can't add it to the table on the html page. 我可以检索数据,但我无法将其添加到html页面上的表中。 Is something wrong with this line?: 这条线有问题吗?:
$("#table_body tbody").append("<tr><td>" + name.Name + "</td><td>" +
user.Email + "</td></td></td></tr>");
the table_body is just the table's id. table_body只是表的id。 The table remains empty. 桌子仍然是空的。 pls help 请帮助
You can add things to a table like this: 您可以像这样向表中添加内容:
function productsAdd() {
$("#productTable tbody").append(
"<tr>" +
"<td>My First Item</td>" +
"<td>6/11/2019</td>" +
"<td>www.itemsite.com</td>" +
"</tr>"
);
}
Is this code running on load? 此代码是否在加载时运行? Is this code wrapper in: 这个代码包装器是:
$(document).ready(function(){});
The document must be loaded before jQuery code can run properly, the function above ensures jQuery inside of it runs after the DOM has loaded 必须在jQuery代码正常运行之前加载文档,上面的函数确保在DOM加载后运行它内部的jQuery
Example: 例:
$(document).ready(function() {
let arr = [{n:'test', e:'ing'}, {n:'stuff', e:'ok'}];
for(let i = 0; i < arr.length; i++) {
$("#table_body tbody").append("<tr><td>" + arr[i].n + "</td><td>" + arr[i].e + "</td></tr>");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.