JSTL标签c:if和c:chose--个人笔记
2016-07-27 16:47
567 查看
<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:choose> 中时,<c:otherwise> 必须为最后一个标签
说明
在同一个 <c:choose> 中,假若所有 <c:when> 的test属性都不为true时,则执行 <c:otherwise> 的本体内容。
范例说明:当condition1为true时,会显示“condition1为true”;当condition1为false且condition2为true时,会显示“condition2为true”,如果两者都为false,则会显示“condition1和condition2都为false”。
<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:forEach items = "${sensorDeviceList}" var = "sensorDevice" varStatus="st"> <c:choose> <c:when test="${sensorDevice.xposition > 0 and sensorDevice.yposition > 0} "> <div id="sensorDevice${sensorDevice.sensorDeviceId}" class = "div" style="left:${sensorDevice.xposition}px;top:${sensorDevice.yposition}px;" onmousedown="drag(this,${sensorDevice.sensorDeviceId},'sensorDevice${sensorDevice.sensorDeviceId}')"> <img alt="图标" src="${pageContext.request.contextPath}/${sensorDevice.parameter.parameterImage.parameterImagePath}">${sensorDevice.sensorDeviceName } </div> </c:when> <c:otherwise> <div id="sensorDevice${sensorDevice.sensorDeviceId}" class = "div2" style="left:85%;top:${st.index*30 + 50}px;" onmousedown="drag(this,${sensorDevice.sensorDeviceId},'sensorDevice${sensorDevice.sensorDeviceId}')"> <img alt="图标" src="${pageContext.request.contextPath}/${sensorDevice.parameter.parameterImage.parameterImagePath}">${sensorDevice.sensorDeviceName } </div> <br/> </c:otherwise> </c:choose> </c:forEach>
<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>成立。相关文章推荐
- 表格标签table深入了解
- WEB标准网页布局中尽量不要使用的HTML标签
- 如何使用jquery easyui创建标签组件
- web标准知识――用途相似的标签
- h1标签的使用技巧
- 探讨JavaScript标签位置的存放与功能有无关系
- HTML代码中标签的全部属性 中文注释说明
- 第九章之路径分页标签与徽章组件
- javascript实现label标签跳出循环操作
- Bootstrap每天必学之标签与徽章
- jQuery EasyUI 布局之动态添加tabs标签页
- jQuery+CSS实现滑动的标签分栏切换效果
- jquery 实现两Select 标签项互调示例代码
- 详解jQuery Mobile自定义标签
- jQuery获取标签文本内容和html内容的方法
- JavaScript获取并更改input标签name属性的方法
- css样式标签和js语法属性区别
- JSP自定义标签入门学习
- JSP中param标签用法实例分析
- jsp之c标签用法实例分析