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 に答える