在JSP页面中使用标签判断字符串长度的问题
比如有个需求,要求后台传递到前台的数据,如果太长就截取一部分后面跟上。。。显示,解决方法:①:在页面初始化时,在js中获取后台传递过来的值,判断长度,长了就截取,再写到标签中如:$(function(){ var filedValue = "<s:property value="filedName"/>";或者${filedName} if(filedValue.length>20){ var testVal = filedValue.substring(0,20)+"..."; $("#test").val(testVal ); } })
②:通过jstl标签直接在html中判断字符长度 推荐使用在jsp页面引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><c:if test="${fn:length(filedName) > 20 }"> ${fn:substring(filedName,0,20)}...</c:if><c:if test="${f:length(filedName) <= 20 }"> ${filedName}</c:if>
②:通过jstl标签直接在html中判断字符长度 推荐使用在jsp页面引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%><c:if test="${fn:length(filedName) > 20 }"> ${fn:substring(filedName,0,20)}...</c:if><c:if test="${f:length(filedName) <= 20 }"> ${filedName}</c:if>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: python实现对指定字符串补足固定长度倍数截断输出
- 下一篇: c语言格式化输出控制长度