Javascript 如何将班级分组进行计算?
我完成了脚本,需要计算每个客户端的小计。 但不知何故,它不想按clientid KLNR分组 我的输出是Javascript 如何将班级分组进行计算?,javascript,jquery,Javascript,Jquery,我完成了脚本,需要计算每个客户端的小计。 但不知何故,它不想按clientid KLNR分组 我的输出是 klnr is: 11111 categorie is: A Subtotal: 4326 HTML: 4326 klnr is: 11111 categorie is: A Subtotal: 748 HTML: 748 klnr is: 11111 categorie is: D klnr is: 22222 categorie is: C Subtotal: 616 HTML: 616
klnr is: 11111
categorie is: A
Subtotal: 4326 HTML: 4326
klnr is: 11111
categorie is: A
Subtotal: 748 HTML: 748
klnr is: 11111
categorie is: D
klnr is: 22222
categorie is: C
Subtotal: 616 HTML: 616
没有klnr 111111的小计
代码如下
$(".KLNR").each(function () {
var klnr = $(this).val();
console.log('klnr is: ', klnr);
if ($.isNumeric($(this).val() )) {
var subtotal = 0;
var categorie = $(this).parent().children(".CATHINT").val();
console.log('categorie is: ', categorie);
if (categorie.contains ("A")||categorie.contains ("C") ){
subtotal = subtotal + parseInt($(this).parent().children(".TOTHINT").val()) ;
console.log("Subtotal: " + subtotal + " HTML: " +
$(this).parent().children(".TOTHINT").val()) ;
}
}
});
根据请求添加HTML代码
<head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE" />
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE" />
<META HTTP-EQUIV="Expires" CONTENT="-1" />
<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="GetCSS" media="screen"></link>
<script language="javascript" type="text/javascript" src="_file/default.js">xslthelper</script>
<title>Wachtrij</title>
<script type="text/javascript" src="_file/jquery.js">xslthelper</script>
<script type="text/javascript" src="_file/JqueryExt.js">xslthelper</script>
<script type="text/javascript" src="_file/cookie.js">xslthelper</script>
<script type="text/javascript">
谢谢你的帮助
或者我应该以不同的方式创建它吗?更改一些内容并检查
var categorie = $(this).parent().children(".CATHINT").val();
将成为
var categorie = $(this).closest(".CATHINT").val();
并删除这条线
subtotal = subtotal + parseInt($(this).parent().children(".TOTHINT").val()) ;
加
subtotal = subtotal + parseInt($(this).closest(".TOTHINT").val()) ;
好的,我已经在脚本中进行了调整并创建了一个数组 现在我有了我想要的输出
Sleutel: 11111
getuser...TILMANR (line 51)
Waarde: 5074
getuser...TILMANR (line 52)
Sleutel: 22222
getuser...TILMANR (line 51)
Waarde: 616
我添加了两行脚本
1 Creation of Array
2 KlnrTotalen[klnr] += subtotal + parseInt($(this).parent().children(".TOTHINT").val()) ;
感谢@Yunus的帮助请提供jsfiddle当我将其更改为“最近”时,我发现该问题不想继续,TypeError:categorie未定义此消息我在下一步收到,如果“最近”已启动,children或“查找”已关闭。如果将父项替换为最近项,则需要将子项更改为查找上述xsl中的html信息我仍然不清楚此设置是否有效,因为最终需要计算klnr is:11111小计:4326 html:4326 klnr is:11111小计:748 html:748 4326+748=小计klnr 111111=5074