Sem mais delongas, vamos apenas olhar para o código
<! xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> js. {// O comprimento do caractere chinês lido pelo atributo de comprimento é 1 se (str.length*2 <= len) {return str; } var strlen = 0; var s = ""; for (var i = 0; i <str.Length; i ++) {s = s+str.Charat (i); if (str.charcodeat (i)> 128) {strlen = strlen + 2; if (strlen> = len) {return s.substring (0, s.Length-1) + "..."; }} else {strlen = strlen + 1; if (strlen> = len) {return s.substring (0, s.Length-1) + "..."; }} else {strlen = strlen + 1; if (strlen> = len) {return s.substring (0, s.Length-2) + "..."; }}} return s var s = CutString (STR, 15); Document.getElementById ('Cut_str'). Innerhtml = S;} </sCript> <div> <p id = "cut_str"> JS Método de escrita que excede o texto é substituído por elipses. </p> </div> </body> </html>Renderizações de implementação
Resumir
De fato, o principal é usar o método substring de JS. Ainda é muito simples implementar essa função, mas é muito prática. O acima é o conteúdo inteiro deste artigo. Espero que este artigo ajude a todos.