JS text Overflow Auto Add ellipsis ellipsis

Source: Internet
Author: User

Original: Ellipsis:function (value, Len, word) {        //Determines if value has exceeded the specified length          if (value && value.length > Len) {     The role of         //word is to try to keep a whole word from being partially omitted              if (word) {                 var vs = Value.substr (0, len-2),                 //guessing the word's bounds                  index = Math.max (Vs.lastindexof ("), Vs.lastIndexOf (' . '), Vs.lastindexof ('! '), Vs.lastindexof ('? ')); /Keep a tolerance length len-15, too short words, affect the performance effect                  if (Index!==-1 && index >= (len-15)) {                     return vs.substr (0, index) + "...";                 }            }             return value.substr (0, len-3) + "...";         }        return value;     }  Modified By:
 functionellipsis (Val, Len, word) {if(Val && val.length >Len) {                if(word) {varvs = Val.substr (0, len-1)                    vari = Math.max (Vs.lastindexof ("), Vs.lastindexof ('. '), Vs.lastindexof ('! '), Vs.lastindexof ('? ')))                    if(I!==-1 && i >= (len-15) ) {                        returnVS.SUBSTR (0, i) + ' ... '                    }                }                returnVal.substr (0, Len) + ' ... '            }            returnVal}

Call Mode:

var aa= "Who are you?" Saada "var bb=ellipsis (aa,5); Console.log (BB);

JS text Overflow Auto Add ellipsis ellipsis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.