从零学习前端开发 2018-02-08
<c:choose>标签与Javascript switch语句的功能一样,用于在众多选项中做出选择。
语法格式
<c:choose>
<c:when test="<boolean>">
...
</c:when>
<c:when test="<boolean>">
...
</c:when>
...
...
<c:otherwise>
...
</c:otherwise>
</c:choose>属性
<c:choose></c:choose>和<c:otherwise></c:otherwise>没有属性
<c:otherwise></c:otherwise>属性只有test如下表
| 属性 | 描述 | 是否必要 | 默认值 |
| test | 条件 | 是 | 无 |
我来举个例子:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>c:choose 标签实例</title>
</head>
<body>
<c:set var="salary" value="15000"/>
<p>你的工资为 : <c:out value="${salary}"/></p>
<c:choose>
<c:when test="${salary <= 1000}">
太惨了,对你表示同情,但又无可奈何。
</c:when>
<c:when test="${salary > 10000}">
不错的薪水,还能生活。
</c:when>
<c:otherwise>
什么都没有。
</c:otherwise>
</c:choose>
</body>
</html> 字符串过于长的时候需要通过仅仅展示前4个,用...表示省略,<c:if test="${fn:length<=5}">${word.type}</c:if>href触发JavaScript事件:。<a