js代码javascript
$(function () {
$(".text_para").each(function (i) {
var divH = $(this).height();
var $p = $("p", $(this)).eq(0);
while ($p.outerHeight() > divH) {
$p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, "..."));
};
});
});
css代码css
.text_para
{
height: 418px;
}
html代码html
Beijing Guardian Dog Equipment Co., Ltd. is a specialized company engaged in Research & Development, production, sales and service of the training equipment supplies for working dog. Thus far, our company has admitted by China Working Dog Management Association with full membership, and is also the annual Vice Chairman of Zhongguo Gongzuo Quanye (zggzqy).
2、同一行超出宽度部分用省略号代替java
1. word-break:break-all;只对英文起做用,以字母做为换行依据
2. word-wrap:break-word; 只对英文起做用,以单词做为换行依据
3. white-space:pre-wrap; 只对中文起做用,强制换行
4. white-space:nowrap; 强制不换行,都起做用
5. white-space:nowrap; overflow:hidden; text-overflow:ellipsis;不换行,超出部分隐藏且以省略号形式出现(部分浏览器支持)