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