用jquery计算价格和TVA

时间:2013-11-15 13:10:13

标签: javascript jquery keyup

我有这个html和JQuery代码: jsfilddle

我的Jquery代码:

$("select#edit-field-tva-percentage-und").on('change', function () {
    var VATpercentage = $("select#edit-field-tva-percentage-und option").filter(":selected").text();
    alert(VATpercentage);
});

jQuery("#edit-field-prezzo-und-0-value").keyup(function () {
    jQuery("#edit-field-totale-documento-und-0-value").val(
        jQuery("#edit-field-prezzo-und-0-value").val()
    );
});

我的问题是: 如何在总计字段中实时显示价格和TVA的计算?

1 个答案:

答案 0 :(得分:1)

这是一个简单的工作示例:

HTML

<select id="vta">
    <option value="21">21</option>
    <option value="15">15</option>
    <option value="12">12</option>
    <option value="10">10</option>
</select>

<div class="form-item form-type-textfield form-item-field-prezzo-und-0-value">
<label for="edit-field-prezzo-und-0-value">Price</label>
<input type="text" class="form-text" maxlength="10" size="12" value="" name="field_prezzo[und][0][value]" id="edit-field-prezzo-und-0-value">
    Total <input type="text" id="total" >

JS

$(function() {
  // Handler for .ready() called.
  $("#vta").on('change', function () {
        updatePrice();
    });

    $("#edit-field-prezzo-und-0-value").keyup(function () {
        updatePrice();
    });
});


function updatePrice(){
    var novta = $("#edit-field-prezzo-und-0-value").val();
    var vta = $("#vta").val();
    var total = novta*vta;
    $("#total").val(total);
}

(编辑)这里的工作示例:http://jsfiddle.net/kELm3/12/