Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="text"><p>我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行</p></div>
    
<div class="text"><p>我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行我要实现多行文本换行</p></div>
</body>
</html>
 
.text {
    background: #EEE;
    width: 410px;
    height: 3em;
    margin: 1em;
}
.text p {
    margin: 0;
    line-height: 1.5em;
}
 
$(".text").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)(\.\.\.)?$/, "..."));
    }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
lexiaoxipro
0viewers