有没有办法将元素和实例传递给事件处理程序回调?
listNotes(key, value){
this.allnotes.insertAdjacentHTML('beforeend', this.constructor.userNoteTemplate(key, value))
this.totalNotes();
let note = document.querySelector(`#note-${key}`);
note.addEventListener("click", this.deleteNote.bind(this));
}
deleteNote(){
let instance = this;
let element = ?// I want the element details also
}
事件处理程序通过一个事件对象,可让您访问各种信息,除其他信息外,处理程序绑定到:
deleteNote(event){
let instance = this;
let element = event.currentTarget;
}