1

我不明白为什么但.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);
        }
});
4

2 回答 2

4

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

于 2012-10-03T20:42:30.413 回答
0

base-price在错误的元素上有类:

<input type="text" name="text[]" placeholder="foo" class="span3 base-price"/>

这解释了NaN响应

这里是固定的:

http://jsfiddle.net/znvHa/5/

于 2012-10-03T20:58:59.177 回答