$(function(){
    delline();
    addline();
    //点击编辑input框
    $(document).on("click",".save",function(){
        var _this = $(this),_thisTxt = _this.text();
        var str = "<input type='text' class='addVal' name='count' value='"+_thisTxt+"' style='width:100px' >";
        _this.addClass("input").html(str).find("input").focus().blur(function(){
            $(this).parent().removeClass("input").html($(this).val()||0);
totalMoney();
//把方法加到这里。
        });
        //alert(str);
    })
     
 
})   function totalMoney(){
var total = 0;
$(".money").each(function(index){
total += $(this).text()-0;
});
console.log(total);
}直接每次都去计算就好了,你修改价钱时,肯定是在blur后才会起作用,所以就把计算的这个函数,放在blur内部就行了

解决方案 »

  1.   

    function totalMoney(){
    var total = 0;
    $(".money").each(function(index){
    var one = $(this).text() - 0;
    if(!!one){
    total += one;
    }
    });
    console.log(total);
    }
    function delline(){
        $(".del").click(function(){
            $(this).closest("tr").remove();
    totalMoney()
        })
    }稍微改一下,上面的没有计算数据是不是可用数据,删除时也得触发这个的~~刚刚也忘记了见谅~~反正大概的意思就是这样的~~