Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LESTADru/8649779 to your computer and use it in GitHub Desktop.
Save LESTADru/8649779 to your computer and use it in GitHub Desktop.
Функция проверяющая длинну сообщения, если длинна больше, то обрезает это сообщение, ставит в конце "...".
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
"use strict";
var str, maxlength;
function truncate(str, maxlength){
if(str.length < maxlength){
return str;
}
return str.slice(0, maxlength-3) + '...';
}
alert(truncate("Вот, что мне хотелось бы сказать на эту тему:", 20));
alert(truncate("Всем привет!", 20));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment