js代码
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/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)(\.\.\.)?$/, "..."));
};
});
});
</script>
css代码
<style>
.text_para
{
height: 418px;
}
</style>
html代码
<div class="text_para"> <p>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).</p></div>