Horizontal and Vertical complicated Javascript Cal

2019-09-03 15:43发布

Now the table is being populated with 2 loops and an array. I have to control everything through the classes I put on the input. Been working on this for a while, some insight would be helpful.

Here is the loop and the inputs:

            <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="R#r# C#i#" onkeypress="return HorizVertiCalc(#r#, #i#)" /></cfif><cfif r EQ 25><input type="text" class="dailyTot#r#" onkeypress="return VertiCalc(#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>

And here is the Javascript I've got at the moment:

         HorizVertiCalc = function(h, v){
            $('.R'+h).sum("keyup", ".ttl"+h);
            $('.C'+v).sum("kepup", ".dailyTot"+h);

            if($('.R'+h) == $('.R4')){
                Number($(this).val()) * <cfoutput>#mileage#</cfoutput>;
                $(this).sum("keypup", ".R5");
                }
            } 

        VertiCalc = function(v){

            alert($('.C'+v));
        }

I need to be able to get the daily totals and the grand total and the totals each category (which I'm able to do right now.). Also, I need to be able to multiply the milage # by the number specific with the variable #mileage# and have the total for that cell be directly below it.

Well. It's a lot and if anyone can give some help, it would be greatly appreciated!

1条回答
一夜七次
2楼-- · 2019-09-03 16:08

Without knowing exactly how your code is working, here are a couple of suggestions/observations:

I notice that you have "keyup", "kepup" and "keypup". Are they all meant to be different?

Not sure what Number() does exactly, but you could use a parseFloat() possibly in conjunction with an isNaN() check before performing the math.

I'm assuming your Javascript code is jQuery? You are doing a jQuery comparison: if($('.R'+h) == $('.R4')) I have a suspicion that this might always return false (as suggested by this page:) http://groups.google.com/group/jquery-en/browse_thread/thread/002d7543186ddaa6

James

查看更多
登录 后发表回答