我有以下html代码:

当我单击delete按钮时,该产品的< li >属性必须删除。
它曾经与JS合作过,但现在却没有这样做。听众:
cartList.on('click', '.delete-item', function(event){
event.preventDefault();
removeProduct($(event.target).parents('.product'));
});这是removeproduct函数,直到它崩溃:
function removeProduct(product) {
clearInterval(undoTimeoutId);
cartList.find('.deleted').remove();
var topPosition = product.offset().top - cartBody.children('ul').offset().top,
productQuantity = Number(product.find('.quantity').find('input').val()),
productTotPrice = Number(product.find('.price').text().replace('€', ''));
}我知道错误:
main.js:168未定义的TypeError:无法读取未定义的属性“top”
因此,他可能无法获得节点产品,而只能读取“操作”--作为父节点的第一个节点。但是如何访问产品li属性来删除整行?
发布于 2017-04-21 11:39:30
尝试使用以下代码片段:
cartList.on('click', '.delete-item', function(event){
$(this).parents('.product').remove(); //this will remove the parent .product from the DOM
});https://stackoverflow.com/questions/43540377
复制相似问题