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>

  • 相关阅读:
    如何写好电子邮件
    【SQL查询】正则表达式匹配字符串_regexp_like/substr/instr/replace
    python_安装第三方库
    【SQL查询】分区查询Over
    【SQL查询】树结构查询
    【PL/SQL编程】块结构
    STL初探
    普及C组第四题(8.18)
    来纪中的的第18天
    来纪中的第十七天
  • 原文地址:https://www.cnblogs.com/lhy2013/p/3648414.html
Copyright © 2011-2022 走看看