表格(TABLE)展示
今天,公司(其實是老闆)要我改程式,而剛好程式的一部分還蠻有趣的,我在下面寫給大家看看。
當中的一部分,要取從今年算起算到二十年前,所以銀幕上要秀出二十"個"年,然後在年的數字旁邊要秀出打勾的框。如果偷懶的寫法的話,會變成像這樣
| 1990 | 1991 | 1992 | 1993 | 1994 |
| 1995 | 1996 | 1997 | 1998 | 1999 |
| 2000 | 2001 | 2002 | 2003 | 2004 |
| 2005 | 2006 | 2007 | 2008 | 2009 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <cfset yr=year(now())-20+1> <table> <cfoutput> <cfloop from="1" to="20" index="i"> <cfif i mod 5 eq 1><tr></cfif> <td>#i+yr#</td> <cfif i mod 5 eq 0></tr></cfif> </cfloop> </cfoutput> </table> |
但是這樣比較讓使用者去找尋他所要的年,如果以下這樣秀的話,就會比較好瀏覽了。
| 1990 | 1994 | 1998 | 2002 | 2006 |
| 1991 | 1995 | 1999 | 2003 | 2007 |
| 1992 | 1996 | 2000 | 2004 | 2008 |
| 1993 | 1997 | 2001 | 2005 | 2009 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <cfset totalCount=20> <cfset rownum=5> <cfset columnum=round(totalCount / rownum)> <cfset yr=year(now())-totalCount+1> <table> <cfoutput> <cfloop from="1" to="#rownum#" index="i"> <tr> <cfloop from="1" to="#columnum#" index="ii"> <cfset yr=yr+rownum> <td>#yr#</td> <cfif i mod 5 eq 0></tr></cfif> </tr> <cfset yr=yr-totalCount+1> </cfloop> </cfoutput> </table> |
No related posts.

其實我覺得第一個比較好瀏覽耶!
嗯 每個人會有不同的意見 就像半杯水滿 還是半杯水空