Created
January 27, 2014 14:46
-
-
Save LESTADru/8649779 to your computer and use it in GitHub Desktop.
Функция проверяющая длинну сообщения, если длинна больше, то обрезает это сообщение, ставит в конце "...".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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