国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery實現文字超過1行、2行或規定的行數時自動加省略號的方法

2019-11-19 14:05:55
字體:
來源:轉載
供稿:網友

本文實例講述了jQuery實現文字超過1行、2行或規定的行數時自動加省略號的方法。分享給大家供大家參考,具體如下:

<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <title>www.survivalescaperooms.com jQuery自動添加省略號</title>  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>  <script type="text/javascript">    $(function () {      $(".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)(/././.)?$/, "..."));        };      });    });  </script>  <style>    *{      padding: 0px;      margin: 0px;    }    .figcaption{      width: 300px;      height: 50px;      /*根據父元素的高度來添加省略號      *可以任意設置顯示的行數      */      border: 1px solid red;    }  </style></head><body>  <div class="figcaption">    <p>      You probably can't do it (currently?) without a fixed-width font like Courier. With      a fixed-width font every letter occupies the same horizontal space, so you could      probably count the letters and multiply the result with the current font size in      ems or exs. Then you would just have to test how many letters fit on one line, and      then break it up.</p>  </div></body><script></script></html>

運行效果:

更多關于jQuery相關內容可查看本站專題:《jQuery字符串操作技巧總結》、《jQuery操作xml技巧總結》、《jQuery擴展技巧總結》、《jquery選擇器用法總結》及《jQuery常用插件及用法總結

希望本文所述對大家jQuery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌兰察布市| 张家界市| 十堰市| 临夏市| 津市市| 介休市| 湟源县| 报价| 芜湖市| 广水市| 鲁甸县| 台东市| 澄江县| 宝鸡市| 万荣县| 仪征市| 荔浦县| 永德县| 阳江市| 芜湖市| 密山市| 岱山县| 辽阳市| 巴林右旗| 惠安县| 葫芦岛市| 平山县| 昆明市| 社旗县| 海伦市| 永福县| 洛浦县| 池州市| 普安县| 文山县| 阳春市| 吴旗县| 神农架林区| 炎陵县| 卓尼县| 霍山县|