国产探花免费观看_亚洲丰满少妇自慰呻吟_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>m.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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 睢宁县| 获嘉县| 新昌县| 凤阳县| 禹州市| 沙坪坝区| 马边| 陇西县| 宁陵县| 保德县| 克什克腾旗| 刚察县| 麟游县| 中西区| 秦安县| 都兰县| 大埔区| 河津市| 泾阳县| 临安市| 久治县| 鹤岗市| 科技| 修文县| 建湖县| 阿坝| 房山区| 文成县| 仙游县| 闽侯县| 大丰市| 新源县| 泽库县| 宁德市| 彰化县| 双鸭山市| 镇雄县| 怀仁县| 廉江市| 江川县| 富裕县|