Jquery help to enforce maxlength on textarea?

前端 未结 4 1907
南方客
南方客 2020-12-31 14:12

Here is Jquery to enforce maxlength for textarea when you add the attribute \"maxlength\". Maxlength is not supported with IE. How do I adjust my code to handle multiple tex

4条回答
  •  忘掉有多难
    2020-12-31 14:58

    This is the best solution! Put this into your script tag in HTML code

    $("textarea[maxlength]").on("propertychange input", function() {
        if (this.value.length > this.maxlength) {
            this.value = this.value.substring(0, this.maxlength);
        }  
    });
    

    and now use for {your limit} chars limit.

提交回复
热议问题