我有以下的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