el 表達式的if else


<c:if>沒有<c:else>可以用<c:choose>來取代結構:
<c:choose>

   <c:when test="">    如果
   </c:when>
   
   <c:otherwise>  否則
   </c:otherwise>
</c:choose>

  
在同一個 <c:choose> 中,當所有 <c:when> 的條件都沒有成立時,則執行 <c:otherwise> 的本體內容。

  語法

  <c:otherwise>

  本體內容

  </c:otherwise>

  屬性

  無

  限制

  ·<c:otherwise> 必須在 <c:choose> 和 </c:choose>之間

  ·在同一個 <c:choose> 中時,<c:otherwise> 必須為最后一個標簽

  說明

  在同一個 <c:choose> 中,假若所有 <c:when> 的test屬性都不為true時,則執行 <c:otherwise> 的本體內容。

  范例

  筆者舉一個典型的 <c:choose>、<c:when>和<c:otherwise>范例:

  <c:choose>

  <c:when test="${condition1}">

  condition1為true

  </c:when>

  <c:when test="${ condition2}">

  condition2為true

  </c:when>

  <c:otherwise>

  condition1和condition2都為false

  </c:otherwise>

  </c:choose>

  范例說明:當condition1為true時,會顯示“condition1為true”;當condition1為false且condition2為true時,會顯示“condition2為true”,如果兩者都為false,則會顯示“condition1和condition2都為false”。

  注意

  假若condition1和condition2兩者都為true時,此時只會顯示"condition1為true",這是因為在同一個<c:choose>下,當有好幾個<c:when>都符合條件時,只能有一個<c:when>成立。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM