Typeerror:无法在`node`上执行`removeChild`:参数1不是`node`

时间:2018-05-15 19:06:29

标签: javascript html firebase

这是一个主键的删除功能,它应该允许我删除数据库中的键以及txtTabell.innerHTML中同一个pk的tablerow,此代码用于工作但突然停止工作。 谢谢你的帮助!

function slett(pk) {
    var sletttime = arrangement.child(pk);
    sletttime.remove();
    var tr = document.getElementById(`${pk}`);
    txtTabell.removeChild(tr);

}

这是txtTabell2.innerHTML中另一个元素的另一个删除函数。

function fjern(pkk) {
    var slettruss = russ.child(pkk);
    slettruss.remove();
}

这些函数显示了innerHTML的内容

    function hentArrangement(snapshot){
    var pk = snapshot.key;
    var nyTime = snapshot.val();
    var russRef = database.ref("russ/" + nyTime.russ);
    russRef.on("value", function(snapshotruss){
        var pkk = snapshotruss.key;
        var russObj = snapshotruss.val();
        txtTabell.innerHTML += `
        <tr id="${pk}">
        <td><label class="russlabel" onclick="edit('${pk}')">${nyTime.arrangør}</label><input type="text" class="editItem" style="display:none"></td>
        <td>${nyTime.adresse}</td>
        <td>${nyTime.postadresse}</td>
        <td>${nyTime.poststed}</td>
        <td>${nyTime.pris}</td>
        <td>${russObj.navn}</td>
        <td>${russObj.russadresse}</td>
        <td>${russObj.mobilnr}</td>
        <td>${russObj.kjonn}</td>
        </tr>`;

        txtTabell2.innerHTML +=`
        <tr =${pkk}>
            <td>${russObj.navn}</td>
            <td>${russObj.russadresse}</td>
            <td>${russObj.mobilnr}</td>
            <td>${russObj.kjonn}</td>
            <td><label class="delete" onclick="slett('${pk},${pkk}')"><button>Slett</button></label></td>
        </tr>`;


    });
} 

function hentRuss(snapshot){
    var russNoekkel = snapshot.key;
    var russInfo = snapshot.val();

    inpRuss.innerHTML += `<option value="${russNoekkel}">${russInfo.navn}</option>`;

};

1 个答案:

答案 0 :(得分:0)

我找到了伙计,我写了这样的删除功能:

function slett(pk,pkk) {
    var slettruss = russ.child(pkk)
    var tr = document.getElementById(`${pkk}`)
    txtTabell2.removeChild(tr);

    var sletttime = arrangement.child(pk);
    sletttime.remove();
    var tr = document.getElementById(`${pk}`);
    txtTabell.removeChild(tr);

}

我删除按钮如下所示:             txtTabell.innerHTML + = <tr id="${pk}"> <td><label class="russlabel" onclick="edit('${pk}')">${nyTime.arrangør}</label><input type="text" class="editItem" style="display:none"></td> <td>${nyTime.adresse}</td> <td>${nyTime.postadresse}</td> <td>${nyTime.poststed}</td> <td>${nyTime.pris}</td> <td>${russObj.navn}</td> <td>${russObj.russadresse}</td> <td>${russObj.mobilnr}</td> <td>${russObj.kjonn}</td> </tr>;

        txtTabell2.innerHTML +=`
        <tr id=${pkk}>
            <td>${russObj.navn}</td>
            <td>${russObj.russadresse}</td>
            <td>${russObj.mobilnr}</td>
            <td>${russObj.kjonn}</td>
            <td><label class="delete" onclick="slett**('${pk}','${pkk}')**"><button>Slett</button></label></td>
        </tr>`;

问题是删除按钮以及我如何编写它们。