如何在isCompleted方法中将css类添加到此类的实例?我尝试过类似的东西,但它没有用?
class Task {
constructor(title, description) {
this._title = title;
this._description = description;
}
addToList () {
let tasksList = document.getElementById('tasksList');
let task = document.createElement('li');
task.setAttribute('class', 'task');
let taskTitle = document.createElement('h3');
taskTitle.setAttribute('class', 'task__title');
taskTitle.innerText = this._title;
let taskDescription = document.createElement('p');
taskDescription.setAttribute('class', 'task__description');
taskDescription.innerText = this._description;
task.appendChild(taskTitle);
task.appendChild(taskDescription);
tasksList.appendChild(task);
};
isCompleted(){
this.classList.add('task-completed');
}
}