如何使用Jquery计算客户端Asp.Net中两个数字的总和 [英] How Do I Calculate Sum Of Two Numbers In Asp.Net At Client Side Using Jquery

查看:47
本文介绍了如何使用Jquery计算客户端Asp.Net中两个数字的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想用jquery对这两个数字求和并在第三个文本框中显示sum

这是我使用的脚本

I just want to sum the two numbers using jquery and shows sum in third textbox
This is the script that i used

<script type="text/javascript">
    $(document).ready(function () {
        var total = 0;
        $('txt_sick_leaves').blur(function () {

            total += parseInt(this.value);


        });

        $('txt_casual_leaves').blur(function () {

            total += parseInt(this.value);

        });
        // Update the total
        $('txt_total_leaves').val(total);
    });
</script>





这是用于从文本框输入值的ASP.NET代码





This is the ASP.NET code for input the values from textbox

<div class="form-group col-md-4">
                <label>Sick Leaves Allowed : </label>
                <asp:TextBox ID="txt_sick_leaves" runat="server" CssClass='form-control' ClientIDMode="Static"

                    placeholder="Number Of Sick Leaves Allowed"></asp:TextBox>
            </div>

            <div class="form-group col-md-4">
                <label>Casual Leaves Allowed : </label>
                <asp:TextBox ID="txt_casual_leaves" runat="server" CssClass='form-control' ClientIDMode="Static"

                    placeholder="Number Of Casual Leaves Allowed"></asp:TextBox>
            </div>

            <div class="form-group col-md-4">
                <label>Total Leaves Allowed : </label>
                <asp:TextBox ID="txt_total_leaves" runat="server" CssClass='form-control' placeholder="Total Leaves Allow" ClientIDMode="Static"></asp:TextBox>
            </div>





请问我的代码中有任何错误然后告诉我更正它

提前感谢你的帮助



Please is there is any mistake in my code then tell me to correct it
thanks in advance for your helps

推荐答案

(文档)。 ready(function(){
var total = 0;
(document).ready(function () { var total = 0;


('txt_sick_leaves')。blur(function(){

total + = parseInt (THIS.VALUE);


});
('txt_sick_leaves').blur(function () { total += parseInt(this.value); });


('txt_casual_leaves')。blur(function(){

total + = parseInt (this.value);

});
//更新总数
('txt_casual_leaves').blur(function () { total += parseInt(this.value); }); // Update the total


这篇关于如何使用Jquery计算客户端Asp.Net中两个数字的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆