Countdown available spaces in a textarea with jquery or other?

后端 未结 9 1176
無奈伤痛
無奈伤痛 2020-12-07 19:17

I have a few areas on my site where I need to limit text input to X amount of characters and it\'s nice to show a number of spaces left while a user types in, like twitter d

9条回答
  •  星月不相逢
    2020-12-07 19:47

    Very simple in jQuery:

    
    

    Substitute the 200 by whatever your limit is.

    Note this does not limit the actual text input, it just counts down. You need to check server-side for the input length, this is just a visual helper.

    As an aside, I don't think you even should try to limit the input length by denying any input when the limit is reached. It's a pain in the rear usability-wise and can't be relied upon anyway. A simple countdown and server-side checking is the best option IMHO.

提交回复
热议问题