Complicated Javascript Calculation

荒凉一梦 提交于 2019-12-11 07:46:00

问题


I've got a fairly large table that needs to have a total on the right side and bottom for daily totals.

I've been able to get the side to total correctly, but not the bottom.

I may be thinking too little of this, but currently I have this: (Yes, I know it's not correct and doesn't work. I was testing)

script:

HorizVertiCalc = function(h, v){
  $('.R'+r).sum("keyup", ".vttl"+v);

  $('.C'+v).sum("keyup", ".vtotal"+r+v);
} 

markup:

<cfloop from="1" to="#ArrayLen(labels)#" index="r">
  <tr>
    <td class="labels"><cfif ArrayIsDefined(labels,r) AND labels[r] NEQ "Open">#labels[r]#</cfif></td>
    <cfloop from="1" to="7" index="i">
      <td id="Day#i#" class="row#r# col#i#">
        <cfif r EQ 1>#Left(DayOfWeekAsString(i),3)#<cfelse><cfif r EQ 2><input type="text" class="date-mask" /><cfelse><input type="text" class="calc R#r# C#i# vtotal#r##i#" onkeypress="return HorizVertiCalc(#r#, #i#)" /></cfif></cfif></td>
    </cfloop>
    <td class="totals"><cfif r EQ 1>Total<cfelse><input type="text" class="ttl#r# vttl#i#" readonly="readonly" /></cfif></td>
  </tr>
</cfloop>

As you can see, I'm producing the table with loops, and so I need to get the total for each column and each row.


回答1:


Does it work if you change line

function(h, v)

to say

function(r, v)

since you are referring to r for the row, not h?

Otherwise, more basically I don't see how $('.R'+r) for instance ever would work, where in here would you end up with anything that has a class .R# ? Granted, I don't know coldfusion



来源:https://stackoverflow.com/questions/1208968/complicated-javascript-calculation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!