jQuery implements the method of limiting the number of characters in the textarea input box

The example of this article describes the method of jquery to limit the number of characters in the textarea input box. Share it with everyone for your reference. The specific analysis is as follows:

the attribute disabled is used to achieve it on the Internet. Of course, this isn't perfect either.

<html>
 <head>
 <title> jquery perfectly implements the limit of characters in the textarea input box</title>
 <meta http-equiv="content-type" content="text/html;charset=utf-8" />
 <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
 <script type="text/javascript">
  $(function(){
   $("#weibo").keyup(function(){
    var len = $(this).val().length;
    if(len > 139){
     $(this).val($(this).val().substring(0,140));
    }
    var num = 140 - len;
    $("#word").text(num);
   });
  });
 </script>
 <style type="text/css">
 h6{color:blue;}
 textarea{resize:none;}
 #word{color:red;}
 </style>
 </head>
 <body>
 <h6>Say something, you can type <span>140</span> characters, now there are <span id="word">140</span> characters</h6>
 <textarea name="con" id="weibo" cols="45" rows="6"></textarea>
 </body>
 </html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326520749&siteId=291194637