Javascript 如何将firebase中的图像url显示到html表中?

Javascript 如何将firebase中的图像url显示到html表中?,javascript,jquery,html,firebase-realtime-database,Javascript,Jquery,Html,Firebase Realtime Database,我对如何在html表中显示图像有一个问题 根据下面的代码,“图像”列仅显示图像的链接,而不显示图像本身。如何将实际图像显示到图像列中 尝试使用以下方法: // put your image url as the url parameter function createImageCell(url) { var td = document.createElement('td'); var img = document.createElement("img"); img.sr

我对如何在html表中显示图像有一个问题

根据下面的代码,“图像”列仅显示图像的链接,而不显示图像本身。如何将实际图像显示到图像列中

尝试使用以下方法:

// put your image url as the url parameter
function createImageCell(url) {
    var td = document.createElement('td');
    var img = document.createElement("img");
    img.src = url;
    td.appendChild(img);
    return td;
}
所以基本上替换tr.appendChildcreateCellimageUrl;使用tr.appendChildcreateImageCellimageUrl

编辑:如果要设置宽度和高度,可以执行以下操作之一:

function createImageCell(url) {
    var td = document.createElement('td');
    var img = document.createElement("img");
    img.src = url;
    img.width = 800; // specify width here
    img.height = 800; // specify height here
    td.appendChild(img);
    return td;
}
或者,如果希望每个图像具有不同的宽度和高度,可以执行以下操作:

function createImageCell(url, width, height) {
    var td = document.createElement('td');
    var img = document.createElement("img");
    img.src = url;
    img.width = width;
    img.height = height;
    td.appendChild(img);
    return td;
}

然后在调用该方法时指定每个图像的宽度和高度。

请提供createCell的代码method@tvicky4j247我已经更新了代码如何设置图像宽度和高度?基本上,将img.width=width和img.height=height添加到createImageCell函数中还有一个问题,为什么我不能使用相同的代码来显示视频?视频播放需要不同的标签,即标签。标记仅适用于图像。您可以显示占位符图像,或者在调用createImageCell方法之前先检查图像url是否为null或为空,将单元格留空。所以做一些类似于if-url{createImageCellurl;}或者{//只创建并返回var-td,而不使用任何img内容}
function createImageCell(url, width, height) {
    var td = document.createElement('td');
    var img = document.createElement("img");
    img.src = url;
    img.width = width;
    img.height = height;
    td.appendChild(img);
    return td;
}