我不明白为什么但.parent()
没有处理动态创建的元素。
这是显示我的问题的小提琴。它计算静态元素的折扣价,而不是创建一个。
$('.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);
}
});