我正在尝试在 javascript 中添加删除按钮,该按钮会在单击时自行删除,但我不知道如何操作。这是我的代码:
<script>
function displayPost(){
var thisDiv = document.getElementById("posts");
var theDate = document.createElement("P");
theDate.classList.add("post-date");
var trash= document.createElement("BUTTON");
trash.classList.add("post-trash");
trash.innerHTML = '<i class="fa fa-window-close" aria-hidden="true"></i>';
thisDiv.appendChild(theDate);
thisDiv.appendChild(trash);
theDate.innerHTML = new Date();
trash.onclick = del(this);
}
function del(x){
var delTrash = document.getElementsByClassName("post-trash");
var delDate = document.getElementsByClassName("post-date");
var index = deltrash.indexof(x);
thisdiv.removeChild(hideTrash[index]);
thisdiv.removeChild(delDate[index]);
}
</script>
抱歉,我对 Javascript 还很陌生。任何形式的帮助表示赞赏。谢谢
拉丁的传说
繁星coding
相关分类