What is the best way to emulate an HTML input “maxlength” attribute on an HTML textarea?

后端 未结 8 1329
执笔经年
执笔经年 2020-11-28 11:54

An HTML text input has an attribute called \"maxlength\", implemented by browsers, which if set blocks user input after a certain number of characters.

An HTML texta

8条回答
  •  半阙折子戏
    2020-11-28 12:55

    Use a JavaScript framework (Prototype, jQuery, etc.) so that you have cross-browser event support. Write a one liner on keyup to prevent the user from entering the maxlength.

    Note: You'll also have to check that length server side.

提交回复
热议问题