jquery text area length count?

后端 未结 5 1150
别跟我提以往
别跟我提以往 2021-02-03 22:21


I have a text area field where i need to provide information about the word count when the user enters some text in the field. Length of the field is supposed to be 500 Ch

5条回答
  •  故里飘歌
    2021-02-03 22:49

    $("#your-text-area").on('keyup', function(event) {
        var currentString = $("#your-text-area").val()
        $("Your Div").html(currentString.length);
        if (currentString.length <= 500 )  {  /*or whatever your number is*/
           //do some css with your div
        } else {
           //do some different stuff with your div
        }
    });
    

    http://api.jquery.com/bind/

提交回复
热议问题