Stop submit button being pressed until enough words are written in text area

后端 未结 6 2100
感动是毒
感动是毒 2021-01-25 17:24

So basically what I want is for the submit button to be disabled until a certain word count has been reached in the text area.

I have had a look around and tried to find

6条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 18:15

    Use the textchange (not built-in) event to accurately detect text changes via keyboard, paste etc. - http://www.zurb.com/playground/jquery-text-change-custom-event

    $('textarea').bind('textchange', function () {
       // $(this).val() contains the new text
    });
    

    In your text-change event, check the length/count the words in your text and enable disable the submit button as needed (make sure its initially disabled).

提交回复
热议问题