Implement the number of words in the front-end text field and prompt for the number of words that can be entered

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">简介</label>
            <div class="layui-input-block">
                <textarea name="note" placeholder="Introduction length within four characters" class="layui-textarea"></textarea>
                <div class="textareaTip">You can also enter <strong id="textareaCount">40</strong> characters</div>
            </div>
        </div>
<script>
 $('textarea').keyup(function(event) {
            /* Act on the event */
            var maxLength = 40;
            var len = $ ('textarea'). val (). length;
            $('#textareaCount').html(maxLength - len);
            if(parseInt($('#textareaCount').text()) < 0){
                $('#textareaCount').html('0');
                var res = $(this).val().substring(0,40);
                $(this).val(res);
            }
        });
</script>

 The above is found on the Internet, only for my own future reference.

Guess you like

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