0

每当按下按钮(按钮不在此代码中)时,我都会尝试进行计数功能。计数的结果应该在只读文本字段中。

var html='';
    var huidig = 0;
    $('body').off('click', '[data-type=product]').on('click', '[data-type=product]', function(e) 
    {
        e.preventDefault();

        var price = $(this).attr('data-price');
        var name =  $(this).attr('data-name');
        var id = $(this).attr('data-id');

        if($('input[value='+id+']').length > 0) 
        {
            var parent = $('input[value='+id+']').parent();
            console.log("parent: " + parent);

            var currentValue = parseFloat(parent.find('input[name^=product_amount]').val());
            console.log("currentValue: " + currentValue);
            currentValue++;
            console.log("currentValue: " + currentValue);

            parent.find('input[name^=product_amount]').val(parseFloat(currentValue));
            console.log(parent.find('input[name^=product_amount]').val(parseFloat(currentValue)));
        }
        else 
        {
            html+='<div class="row-fluid"><div class="span1"><input type="hidden" name="product[]" value="'+id+'"/><input type="text" readonly="readonly" name="product_amount[]" value="0" /></div>  <div class="span7">'+name+'</div>  <div class="span3 offset1">&euro;'+price+'</div>  </div>';
        }

        $('.bill').html(html);
        amount = amount + parseFloat(price);
        $('.total_bill').html(amount.toFixed(2));
    });
4

0 回答 0