文字溢出

1.常规css方法——使Firefox以外主流浏览器文字溢出省略号表示
.zxx_text_overflow{
27em;
white-space:nowrap;
text-overflow:ellipsis;
-o-text-overflow:ellipsis; overflow:hidden;
}


已经封装好了的jq

//超过35个字符 其他显示...
$(function () {
$(".ellipsis").each(function () {
var maxwidth = 30;
if ($(this).text().length >= maxwidth) {
var b = $(this).children().is("a");
if (b) {
$(this).children().text($(this).children().text().substring(0, maxwidth) + "...");
} else {
$(this).text($(this).text().substring(0, maxwidth));
$(this).text($(this).text() + "...");
}

}
});
});

原文地址:https://www.cnblogs.com/zhoubingyan/p/8439683.html