javascript - Limit the number of newline of dynamic textarea in jquery -
I am trying to limit the number of a new line that can be entered in a dynamic textrera, but I The code that is created is not working. I have to set at least 4 new lines that the user can do. In addition I have set the maximum characters to 40 characters.
Here's my code.
$ (document) .ready (function () {$ ("[name = 'memo []']"). Each (function () {$ (This) .keydown (function) () {NewLines = $ (this) .val (). Partition ("\ n") Length; $ (this) .text (newLines); if (e.keyCode == 13 and Newlines = 4) { Warning ("forward"); return false;}});});});
Try it out:
$ (document) Each function () {var textarea = $ (this); Textarea.attr ('maxlength', 40); Textarea.keydown (function (e) {var newLines = textarea.val (.) Partition (/ \ r * \ n /) length; if (e.keyCode === 13 & amp; amp; amp; new & Gt; = 4) {Prevent error.};}}); }); }); UPDATE : Do not warn and the code works properly Demo link is:
Comments
Post a Comment