Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用jQuery计算表列值_C#_Javascript_Jquery - Fatal编程技术网

C# 使用jQuery计算表列值

C# 使用jQuery计算表列值,c#,javascript,jquery,C#,Javascript,Jquery,我有一些表格&我需要计算列值。在我的场景中,我需要将商品总价99+55=154计算为小计行。在这里,小计计算不起作用 我的代码(我的表创建的一部分) 您可以更改此设置: $.each($('.tot'), function (element) { $(lastrow).find("td:eq(5)").html(element); }); 为此: var total = 0; // intialise a var with value 0 $('.tot').eac

我有一些表格&我需要计算列值。在我的场景中,我需要将商品总价99+55=154计算为小计行。在这里,小计计算不起作用

我的代码(我的表创建的一部分)

您可以更改此设置:

$.each($('.tot'), function (element) {
   $(lastrow).find("td:eq(5)").html(element);
});
为此:

var total = 0; // intialise a var with value 0
$('.tot').each(function (i, element) { // loop the selected item in each row
   total += +$(this).text(); // cast the string to integer and add it to total
});
$(lastrow).find("td:eq(5)").text(total); // then at last place the total


简而言之:

.live()
现在已从最新的jQuery版本中删除,因此如果您使用的是
版本1.7+
,则可以将代码移动到
.on()
方法来委派事件。事件委派的语法如下所示:

$(static_parent).on(event, selector, callback);
$(static\u parent)
是相对dom就绪时可用的元素,在页面中添加任何动态dom元素之前,该元素当时可用

因此,在你的情况下:

$('table_ID/Class').on('click', '.btncalc', function(){
    //...all the stuff with .live goes here
});
$(static_parent).on(event, selector, callback);
$('table_ID/Class').on('click', '.btncalc', function(){
    //...all the stuff with .live goes here
});