Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果在JavaScript中单击了子项,则删除父项_Javascript_Html_Html Lists_Addeventlistener - Fatal编程技术网

如果在JavaScript中单击了子项,则删除父项

如果在JavaScript中单击了子项,则删除父项,javascript,html,html-lists,addeventlistener,Javascript,Html,Html Lists,Addeventlistener,我在创建ToDoApp时遇到问题 如果我点击图标,图标应该从图标所在的位置移除。 我无法编写一个函数,它先升到span,再升到li,然后将其删除 const input=document.querySelector('input'); const list=document.querySelector('ul'); const reset=document.querySelector('.reset'); const addTask=(e)=>{ if(e.keyCode==13&&input

我在创建ToDoApp时遇到问题

如果我点击图标,图标应该从图标所在的位置移除。 我无法编写一个函数,它先升到span,再升到li,然后将其删除

const input=document.querySelector('input');
const list=document.querySelector('ul');
const reset=document.querySelector('.reset');
const addTask=(e)=>{
if(e.keyCode==13&&input.value.length!=0){
设value=input.value;
const li=document.createElement('li');
const span=document.createElement('span');
const icon=document.createElement('i');
icon.classList.add('material-icons');
icon.textContent=“highlight_off”;
span.appendChild(图标);
li.textContent=值;
//setAttribute(“onclick”,`deleteTask()`);
表1.儿童(李);
李.儿童(span);
input.value=“”;
}
}
常量deleteTask=(e)=>{
常量元素=e.目标;
控制台日志(元素);
element.currentTarget.parentNode.remove();
}
input.addEventListener('keydown',addTask);
list.addEventListener('click',deleteTask)

    //这里是李
清楚的
使用最近的

const input=document.querySelector('input');
const list=document.querySelector('ul');
const reset=document.querySelector('.reset');
const addTask=(e)=>{
if(e.keyCode==13&&input.value.length!=0){
设value=input.value;
const li=document.createElement('li');
const span=document.createElement('span');
const icon=document.createElement('i');
icon.classList.add('material-icons');
icon.textContent=“highlight_off”;
span.appendChild(图标);
li.textContent=值;
//setAttribute(“onclick”,`deleteTask()`);
表1.儿童(李);
李.儿童(span);
input.value=“”;
}
}
常量deleteTask=(e)=>{
常量元素=e.目标最近(“li”);
控制台日志(元素);
元素。移除();
}
input.addEventListener('keydown',addTask);
list.addEventListener('click',deleteTask)

    //这里是李
清楚的