我有以下的html代码: 获得从父节点父在JS
当我点击删除按钮从该产品的< 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 Uncaught TypeError: Cannot read property 'top' of undefined
所以他很可能无法获得该节点的产品但只读取“动作” - 作为父节点的第一个节点。但是,我怎么能存取权限的产品里属性删除整个行
'cartBody.children( 'UL')偏移()''是undefined'。什么是'cartBody'?它是否有任何儿童'ul'元素? –
如果您有问题需要显示HTML,请将其包含为文本,而不是图片,以便相关人员可以轻松地将其复制到答案中。 – nnnnnn
html是用javascript编码的 – belgiums