您的位置:首页 > Web前端 > JavaScript

JSTL 字符串长度判断并截取

2017-09-28 00:00 197 查看
应用场景:

如新闻列表展现时,超过长度的新闻截取前几个文字,后边的用 ... 表示。如下图所示:

参考代码:

[html] view plain copy

<c:forEach items="${newslist}" var="news" varStatus="vs">

<li>

<a href="${ctx}/news/newsQueryById.html?id=${news.id}">

<span>

${fn:substring(news.writetime,0,10)}

</span>

<c:if test="${fn:length(news.title)>'13'}">

${fn:substring(news.title,0,13)}...

</c:if>

<c:if test="${fn:length(news.title)<='13'}">

${news.title}

</c:if>

</a>

</li>

</c:forEach>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: