3

<cfoutput>在表格中放置了地址变量。我遇到的问题是这些变量有时为空,但由于换行符,它们仍然占用表中的空间。

   <td>  
    <cfoutput>
       #getMeeting.meetingDemographicsAddressLine1#<br />
       #getMeeting.meetingDemographicsAddressLine2#<br />
       #getMeeting.meetingDemographicsCity#
    </cfoutput>
   </td>

<br />如果变量为空,如何让浏览器忽略标签?

4

2 回答 2

5

您可以使用创建打印行函数cffunction并使用它cfif来检查值的长度是否超过 0。即

确保您实际上也表示 null,请参阅http://www.bennadel.com/blog/1654-Learning-ColdFusion-9-IsNull-And-Working-With-NULL-Values.htm

例子

<cffunction name="PrintLine" returntype="void">
  <cfargument name="Value" />
  <cfif len(arguments.Value) GT 0>
    <cfoutput>#arguments.Value#<br /></cfoutput>
  </cfif>
</cffunction>

或从函数返回:-

<cffunction name="PrintLine2" returntype="string">
  <cfargument name="Value" />
  <cfset var foo = "" />
  <cfif len(trim(arguments.Value)) GT 0>
    <cfset foo = arguments.Value & "</br />" />
  </cfif>
  <cfreturn foo />
</cffunction>

可以根据需要添加您的返回类型/提示/必需属性

文档

请参阅http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_f_21.html

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_i_01.html

然后你可以这样做: -

<td>  
  <cfoutput>
   #PrintLine(getMeeting.meetingDemographicsAddressLine1)#
   #PrintLine(getMeeting.meetingDemographicsAddressLine2)#
   #getMeeting.meetingDemographicsCity#
  </cfoutput>
</td>
于 2013-04-15T09:57:47.697 回答
0
    <cfoutput>
    <cfif len(getMeeting.meetingDemographicsAddressLine1) gt 0 >
           #getMeeting.meetingDemographicsAddressLine1#
    </cfif>
    <cfif len(getMeeting.meetingDemographicsAddressLine2) gt 0 >
           <br />#getMeeting.meetingDemographicsAddressLine2#
    </cfif>
    <cfif len(getMeeting.meetingDemographicsCity) gt 0 >
            <cfif len(getMeeting.meetingDemographicsAddressLine1) gt 0 or  len(getMeeting.meetingDemographicsAddressLine2) gt 0>
                 <br />#getMeeting.meetingDemographicsCity#
            <cfelse>
                #getMeeting.meetingDemographicsCity#
            </cfif>
    </cfif>
</cfoutput>
于 2013-04-15T09:59:04.970 回答