<c:otherwise>是一種計算機編程的語言

簡介,語法,注意,

簡介

在同一個 <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>成立。

相關詞條

熱門詞條

聯絡我們