方法一:
使用<c:foreach>控制显示字数
将下面的方法嵌套在标签上:
<c:if test="${fn:length(learningAssociate.associateLearningTitle)>12}">
${fn:substring(learningAssociate.associateLearningTitle, 0, 12)}...
</c:if>
<c:if test="${fn:length(learningAssociate.associateLearningTitle)<=12}">
${learningAssociate.associateLearningTitle}
</c:if>
方法二
利用js方法,字符串切割:
function getFixedLengthStr(str, length) {
if (str != undefined) {
if (str.length > 8) {
return str.substring(0, length) + '..';
} else {
return str;
}
} else {
return '';
}
}
如果需要鼠标放上显示全部,可以在标签里面加上title属性,并且赋值需要展示的数据。
再填上一下的css样式:
自己可以再控制标签的长度。
style="display :inline-block ;overflow: hidden;textOverflow: ellipsis;whiteSpace: nowrap"