Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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
带有动态DOM的Javascript get clicked元素_Javascript_Html_Dom_Dom Manipulation - Fatal编程技术网

带有动态DOM的Javascript get clicked元素

带有动态DOM的Javascript get clicked元素,javascript,html,dom,dom-manipulation,Javascript,Html,Dom,Dom Manipulation,我在一张纸条上打呼噜,在纸条上我在桌子上创建了一组行。在最后一列()中,我添加了一个图标来删除该行。在创建行()时,我在图标中添加了一个调用函数的eventListner,到目前为止,在该函数上,我只在控制台上显示一条消息,以检查我是否正确捕获了事件,并且它工作正常。现在我尝试获取包含图标的父元素(),以便将其从表中删除 这是我现在的代码: 此函数用于创建新行: const addProductCart = () => { const cartRow = document.create

我在一张纸条上打呼噜,在纸条上我在桌子上创建了一组行。在最后一列()中,我添加了一个图标来删除该行。在创建行()时,我在图标中添加了一个调用函数的eventListner,到目前为止,在该函数上,我只在控制台上显示一条消息,以检查我是否正确捕获了事件,并且它工作正常。现在我尝试获取包含图标的父元素(),以便将其从表中删除

这是我现在的代码:

此函数用于创建新行:

const addProductCart = () => {


const cartRow = document.createElement('tr'); 
cartRow.classList.add("itemRow");



const productColumn = document.createElement('td');
productColumn.innerHTML = optionList.options[optionList.selectedIndex].text; 
cartRow.appendChild(productColumn); 


const unitsColumn = document.createElement('td');
unitsColumn.innerHTML = units.value;
cartRow.appendChild(unitsColumn);


const unitPrice = document.createElement('td');
unitPrice.innerHTML = optionList.value;
cartRow.appendChild(unitPrice);


const totalPrice = document.createElement('td');
totalPrice.innerHTML = optionList.value * units.value;
cartRow.appendChild(totalPrice);


const removeButton = document.createElement('img');
removeButton.setAttribute("src", "data/icons/detele1.svg");
removeButton.classList.add("icon");
removeButton.addEventListener('click', eraseProduct); 
cartRow.appendChild(removeButton);


carritoFila.appendChild(cartRow);  

}
每次单击“擦除”按钮时,都会启动此功能:

const eraseProduct = () => {
    console.log(`clic`);
}
使用编辑器中的
按钮创建。
const-eraseProduct=(事件)=>{console.log(event.target.parentNode);}