js beyond text to show the number of ellipsis

method one:

function wordlimit(cname, wordlength) {
    var cname = document.getElementsByClassName(cname);
    for (var i = 0; i < cname.length; i++) {      
        var nowLength = cname[i].innerHTML.length;
        if (nowLength > wordlength) {
            cname[i].innerHTML = cname[i].innerHTML.substr(0, wordlength) + '...';
        }      
    } 
};

Method Two:

fontNumber (date) {
  const length = date.length
  if (length > 30) {
    var str = ''
    str = date.substring(0, 30) + '......'
    return str
  } else {
    return date
  }
}

Guess you like

Origin blog.csdn.net/qq_24147051/article/details/92773126