如果行是当前日期,则插入锚点

Nie*_*che 2 coldfusion coldfusion-9

我们有一个使用部分代码动态生成的计划:

    <cfloop from="0" to="6" index="x">
        <cfset thisDate = dateFormat(dateAdd("d",x,theDate),"yyyy-mm-dd")>
        <cfoutput><tr><td colspan="4" class="date"><strong>#dateFormat(thisDate,"DDDD, M/D")#</strong></td></tr></cfoutput>
        <cfif structKeyExists(dayData,thisDate)>
            <cfif arrayLen(dayData[thisDate]) gt 0>
                <cfloop from="1" to="#arrayLen(dayData[thisDate])#" index="y">
                    <cfoutput><tr>#dayData[thisDate][y]#</tr></cfoutput>
                </cfloop>
            <cfelse>
                <cfoutput><tr><td colspan="4">There are no classes scheduled for this day</td></tr></cfoutput>
            </cfif>
        <cfelse>
            <cfoutput><tr><td colspan="4">Schedule not available</td></tr></cfoutput>
        </cfif>
    </cfloop>
Run Code Online (Sandbox Code Playgroud)

我要做的是动态插入一个锚(例如,<a name ="anchor">),具体取决于显示行中的日期是否是当前日期.所以我想要一个cfif,它将在日程表的当天一行显示锚点.目标是使用锚链接到此.

任何建议都非常感谢.

Jas*_*ean 5

这样的事情呢?

<cfif dateFormat(now()),"yyyy-mm-dd") eq thisDate>
    <a name="anchor" />
</cfif>
Run Code Online (Sandbox Code Playgroud)

BTW,你知道你可以在ColdFusion中循环日期吗?

<cfloop from="#theDate#" to="#dateAdd("d", 6, theDate)#" index="thisDate" step="#CreateTimeSpan( 1, 0, 0, 0 )#">
</cfloop>
Run Code Online (Sandbox Code Playgroud)

这假定日期采用CF看作日期的格式,就像now()返回的那样.