Character countdown like on twitter

后端 未结 9 925
栀梦
栀梦 2020-12-02 06:54

How can I make a \"remaining characters\" countdown like the one on Twitter with jQuery? And also limit the input to a textarea.

9条回答
  •  -上瘾入骨i
    2020-12-02 07:06

    I've used Aaron Russell's simply countable jQuery plugin with success; though, if I were to have written it, I would have designed it a bit differently (automatic counter div creation, using a data-maxlength attribute instead of a plugin option, etc).

    Simple usage:

    $('#my_textarea').simplyCountable();
    

    Advanced usage:

    $('#my_textarea').simplyCountable({
        counter: '#counter',
        countable: 'characters',
        maxCount: 140,
        strictMax: false,
        countDirection: 'down',
        safeClass: 'safe',
        overClass: 'over',
        thousandSeparator: ','
    });
    

提交回复
热议问题