早睡早起,方能养生
Sleep early rise early, way to keep healthy

JS控制textarea输入的字数

super
2023-12-13 18:07
views 573

JS控制textarea输入的字数,输入的超出就删除

 

<textarea class="form-control" name="content" rows="5" required="required" placeholder="最多显示55个字" id="commentarea" onKeyDown="LimitTextAreaLength(this)" onKeyUp="LimitTextAreaLength(this)" onkeypress="LimitTextAreaLength(this)" ></textarea>

 

<script>

    function LimitTextAreaLength(obj) { 
        let allow_input = 55; 
        if (obj.value.length > allow_input) 
            obj.value = obj.value.substring(0, allow_input); 
    }
</script>

 



分享
0 条讨论
top