gpt4 book ai didi

javascript - parent() 不适用于事件元素

转载 作者:行者123 更新时间:2023-11-30 10:38:23 25 4
gpt4 key购买 nike

我不明白为什么 .parent() 不能处理动态创建的元素。

这里是 fiddle显示我的问题。它计算静态元素的折扣价,而不是创建的元素。

$('.item-sizes .discount-percent').live('keydown', function () {
var percentValue = $(this).val();
var basePrice = $('.base-price', $(this).parent().parent()).val(); // Undefine on live elements, defined on static

if (basePrice) {
discountValue = basePrice - ((percentValue / 100) * basePrice);
$('.discount-price', $(this).parent().parent()).val(discountValue);
}
});

最佳答案

您要添加 的 HTML 在任何地方都没有 base-price 类。

关于javascript - parent() 不适用于事件元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12716530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com