我在下面的代码中调用close函数时卡住了。该程序为工作日创建了一个新的内容。在穿上必要的地方后,如果用户想要删除close.setSttribute("onclick", "removeItem(this,event)");
函数必须调用的内容。但在我的代码中出了问题。请帮忙修复调用该功能。
function addClick() {
var weekday = document.getElementById("weekdaysModal").value;
var name = document.getElementById("fname").value;
var itemContent = document.getElementById("textArea").value;
var divItem = document.createElement("div");
divItem.setAttribute("class", "divItem");
var close = document.createElement("img");
close.setAttribute("class", "close");
close.setAttribute("src", "./img/delete.png");
close.setAttribute("onclick", "removeItem(this, event)");
close.setAttribute("width", "20px");
close.setAttribute("height", "20px");
console.log(close);
divItem.appendChild(close);
var textDiv = document.createElement('div');
textDiv.setAttribute("class", "name");
textDiv.innerHTML = name;
divItem.appendChild(textDiv);
var content = document.createElement('div');
content.setAttribute("class", "itemContent");
content.innerHTML = itemContent;
content.style.display = 'none';
divItem.appendChild(content);
if (weekday == "monday") {
// divItem.setAttribute("index", monIndex);
divItem.style.background = "#d4f442";
document.getElementsByClassName('displayArea_mon')[0].appendChild(divItem);
} else if (weekday == "tuesday") {
// divItem.setAttribute("index", tueIndex);
divItem.style.background = "#65f441";
document.getElementsByClassName('displayArea_tue')[0].appendChild(divItem);
} else if (weekday == "wednesday") {
console.log("wed");
// divItem.setAttribute("index", wedIndex);
divItem.style.background = "#65f441";
document.getElementsByClassName('displayArea_wed')[0].appendChild(divItem);
} else if (weekday == "thursday") {
// divItem.setAttribute("index", thuIndex);
divItem.style.background = "#65f441";
document.getElementsByClassName('displayArea_thu')[0].appendChild(divItem);
} else if (weekday == "friday") {
// divItem.setAttribute("index", friIndex);
divItem.style.background = "#65f441";
document.getElementsByClassName('displayArea_fri')[0].appendChild(divItem);
} else {
console.log("Error");
}
closeButton();
console.log(name + content + weekday);
}
function removeItem() {
var x = getElementsByClassName('divItem');
x.delete(x.selectedIndex);
}