日期:2014-05-20  浏览次数:20620 次

EL表达式截取字符串后加"..."问题
想要做的效果:栏目标题栏目标题栏...

本人用spring的MVC 
我在 Control层获取一个list 之后 向jsp 页面转发

jsp 页面 我用 el 表达式获取

list 里面的东西

${fn:substring(schedulelist.content, 0, 10)}

EL表达式能不能自动判断 如果超出的话 可以自动加上那个“...”





------解决方案--------------------
HTML code
<c:set var="str" value="abcdefghijklmnopqrstuvwxyz" /> 
<c:choose> 
<c:when test="${fn:length(str) > 10}"> 
<c:out value="${fn:substring(str, 0, 10)}......" /> 
</c:when> 
<c:otherwise> 
<c:out value="${str}" /> 
</c:otherwise> 
</c:choose>

------解决方案--------------------
EL没有自动判断功能,必须你自己判断进行处理。
------解决方案--------------------
HTML code
<style type="text/css">
.ellipsis a{display: block;width: 300px;overflow: hidden;white-space: nowrap;-o-text-overflow: ellipsis;text-overflow:ellipsis;}   
/* firefox only */  
.ellipsis:not(p) {clear: both;}   
.ellipsis:not(p) a {max-width: 300px;float: left;}   
.ellipsis:not(p):after {content: "...";float: left;width: 25px;padding-left: 1px;}  
</style>
  <body>
    <div class="ellipsis"><a href="">如果文字太长将会被截取后面字符使用省略号代替</a></div>
  </body>