用jquery 实现 超出字符 截断加上省略号并且可以提示全部内容
用jquery 实现 超出字符 截断加上省略号并且可以提示全部内容
1.test.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="${webRoot}/framework/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${webRoot}/framework/js/jquery-ui.js"></script>
<script type="text/javascript" src="${webRoot}/framework/js/strlimit.js"></script>
<script>
$('table').tooltip();
</script>
</head>
<table>
<tr>
<td class="centerContentTd" nowrap="nowrap" title="这里是全部内容" limit="8">这里显示截取后的内容
长度大于8将用省略号代替</td>
</tr>
</table>
</html>2.strlimit.js
jQuery.fn.limit=function(){
var self = $("[limit]");
self.each(function(){
var objString = $(this).text();
var objLength = $(this).text().length;
var num = $(this).attr("limit");
if(objLength > num){
$(this).attr("title",objString);
objString = $(this).text(objString.substring(0,num) + "...");
}
})
}
$(function(){
$("[limit]").limit();
}) 相关推荐
Zhongmeishijue 2020-09-10
runner 2020-09-01
梦的天空 2020-08-25
IdeaElements 2020-08-19
luvhl 2020-08-17
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
NARUTOLUOLUO 2020-08-03
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
OldBowl 2020-06-26
北京老苏 2020-06-25
Luffyying 2020-06-25