zoukankan      html  css  js  c++  java
  • js 实现省略号在左边显示

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    #container {
    200px;
    border: 1px solid blue;
    }
    #container div {
    100%;
    overflow: hidden;
    white-space: nowrap;
    }
    </style>
    <script>
    function trimRows() {
    var rows = document.getElementById('container').childNodes;
    for (var i=0, row; row = rows[i]; i++)
    {
    if (row.scrollWidth > row.offsetWidth) {
    var textNode = row.firstChild;
    var value = '...' + textNode.nodeValue;
    do {
    value = '...' + value.substr(4);
    textNode.nodeValue = value;
    } while (row.scrollWidth > row.offsetWidth); }
    }
    }
    </script>
    </head>
    <body onload='trimRows();'>
    <div id="container" >
    <div>first > second > third</div>
    <div>second > third > fourth > fifth > sixth</div>
    <div>fifth > sixth > seventh > eighth > ninth</div>​
    </div>





    <style>
    p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    170px;
    border:1px solid #999;
    direction:rtl;
    text-align:left;
    }
    </style>
    <p>first &gt; second &gt; third<br />
    second &gt; third &gt; fourth &gt; fifth &gt; sixth<br />
    fifth &lt; sixth &lt; seventh &lt; eighth &lt; ninth</p>

    <script>
    var text = $( 'p' ).text(),
    split = text.split( ' ' ),
    finalStr = '';
    for( i in split ){
    finalStr = finalStr.length > 0 ? finalStr + '<br />' : finalStr;
    var match = /(w+s?(<|>)?s?){3}$/.exec( split[i] );
    finalStr = finalStr + ( split[i].length > match[0].length ? '...' : '' ) + match[0]; } $( 'p' ).empty().html( finalStr );
    </script>






    </body>
    </html>

  • 相关阅读:
    单词接龙
    洛谷 P1015 回文数
    洛谷 P1012 拼数
    codevs 2780 ZZWYYQWZHZ
    专项练习之字符串
    模拟题1
    专项训练之线段树
    复习题之求后序遍历
    复习题之二叉树的遍历
    Hdu 3037 Saving Beans(Lucus定理+乘法逆元)
  • 原文地址:https://www.cnblogs.com/lhy2013/p/3648414.html
Copyright © 2011-2022 走看看