Java Script Vat正确计算函数不计算

时间:2016-10-20 05:01:45

标签: javascript asp.net

我尝试写 JavaScript 增值税计算增值税15%实际上它没有正确计算我该如何解决它,

总金额= 9000 增值税(+)%= 15% 1350

的Javascript

<script type="text/javascript">

        //Vat Calculate
        $(function () {

            $('#txtGrossAmount').on('input', function () {
                calculate();
            });
            $('#txtVatno').on('input', function () {
                calculate();
            });
            function calculate() {
                var pPos = parseInt($('#txtGrossAmount').val());
                var pEarned = parseInt($('#txtVatno').val());
                var perc = "";
                if (isNaN(pPos) || isNaN(pEarned)) {
                    perc = " ";
                } else {
                    perc = ((pEarned / pPos) * 100).toFixed(3);
                }

                $('#txtTax').val(perc);
            }

        });
</script>

ASP.NET

<div class="col-md-4" style="margin-left:15px; margin-top:55px">
    <div class="row">
        <div class="col-md-6">
            <asp:Label ID="Label18" runat="server" Text="Gross Amount" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
        </div>
        <div class="col-md-6">
            <asp:TextBox ID="txtGrossAmount" ClientIDMode="Static" runat="server" CssClass="form-control boxDisable"></asp:TextBox>
            </div>
    </div>

    <div class="row">
        <div class="col-md-6" style="margin-top:5px">
            <asp:Label ID="Label25" runat="server" Text="VAT(15%)" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
            <asp:Label ID="Label26" ClientIDMode="Static" runat="server" Text="" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
        </div>
        <div class="col-md-6" style="margin-top:5px">
            <asp:TextBox ID="txtVatno" ClientIDMode="Static" runat="server" CssClass="form-control boxDisable"></asp:TextBox>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6" style="margin-top:5px">

            <asp:Label ID="lblTax" ClientIDMode="Static" runat="server" Text="" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
        </div>
        <div class="col-md-6" style="margin-top:5px">
            <asp:TextBox ID="txtTax" ClientIDMode="Static" runat="server" CssClass="form-control boxDisable"></asp:TextBox>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

它正在发挥作用 的 ASP.NET                                                                                                                 

    <div class="row">
        <div class="col-md-6" style="margin-top:5px">
            <asp:Label ID="Label25" runat="server" Text="VAT(15%)" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
            <asp:Label ID="Label26" ClientIDMode="Static" runat="server" Text="" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
        </div>
        <div class="col-md-6" style="margin-top:5px">
            <asp:TextBox ID="txtVatno" ClientIDMode="Static" runat="server" CssClass="form-control boxDisable"></asp:TextBox>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6" style="margin-top:5px">

            <asp:Label ID="lblTax" ClientIDMode="Static" runat="server" Text="" Font-Bold="True" Font-Names="arial, helvetica, sans-serif" Font-Size="13px"></asp:Label>
        </div>
        <div class="col-md-6" style="margin-top:5px">
            <asp:TextBox ID="txtTax" ClientIDMode="Static" runat="server" CssClass="form-control boxDisable"></asp:TextBox>
        </div>
    </div>
</div>  

<强>的jQuery

$(function () {

$('#txtGrossAmount').on('input', function () {
    calculate();
});
$('#txtVatno').on('input', function () {
    calculate();
});
function calculate() {
    var PPos = parseInt($('#txtGrossAmount').val());
    var PEarned = parseInt($('#txtVatno').val());
    var perc = "";
    if (isNaN(PPos) || isNaN(PEarned)) {
        perc = " ";
    } else {
        perc = ((PPos / 100) * PEarned).toFixed(3);
    }

    $('#txtTax').val(perc);
}

});