使用 jquery 计算价格和 TVA

Calculate price and TVA with jquery

本文关键字:TVA jquery 计算 使用      更新时间:2023-09-26

我有这个html和JQuery代码:斯菲尔德尔

我的 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 的计算结果?

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

.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/