Limiting number of lines and letters in single line in textarea

前端 未结 4 1592
感情败类
感情败类 2020-12-18 08:39

Problem:
I am trying to limit number of lines AND letters in each line in a textbox.

What i got so far:
So far i managed t

4条回答
  •  臣服心动
    2020-12-18 09:32

    Instead of looping over each line get the current line number of your cursor and check only the character length of that line. See this SO answer for implementation details.

    Then change your else statement to look like this:

    else{
        var currLine = getLineNumber();
        if (lines[currLine].length >= $(this.attr('cols')) {
            return false; // prevent characters from appearing
        }
    }
    

提交回复
热议问题