引用Jquery網站
$(".figcaption").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)(\.\.\.)?$/, "..."));
};
});this
<div class="figcaption"><p>固定一個喜歡的網站可不能夠?固然!把天天常去的網站通通固定到開始屏幕中。如何固定?打開 IE10,在網頁空白處點擊鼠標右鍵,在應用欄中點擊「圖釘」圖標便可完成固定。</p></div>io
樣式:function
.figcaption {
background: #EEE;
width: 410px;
height: 3em;
margin: 1em;
}
.figcaption p {
margin: 0;
line-height: 1.5em;
}class