jsp页面,一行文字中超过指定字数,显示省略号...

方法一:一个标签加样式解决
<td style="max-width:200px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis">${item.alg_categoryname}</td>
各种样式缺一不可
CSS:需要加上宽度(width:100px)、
超出隐藏(overflow:hidden;)、
强制在同一行显示(white-space: nowrap;)、
省略号(text-overflow:ellipsis;)


方法二:
引入taglib
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

具体代码中,if标签
<td>
    <c:if test="${fn:length(item.alg_categoryname) > 25}">${fn:substring(item.alg_categoryname, 0, 25)}...</c:if>
    <c:if test="${fn:length(item.alg_categoryname) <= 25}">${item.alg_categoryname}</c:if>
</td>

猜你喜欢

转载自blog.csdn.net/qq_39822451/article/details/82753153