jquery计算文本域中的值

jquery计算文本域中的值

('.sr').on('keyup','#sr_txt',function(){
    if($(this).val().length > 100){
        $(this).val( $(this).val().substring(0,100) );
    }
        $(".sr_span span").html(100 - $(this).val().length) ;
})

介绍以下思路
这里采用事件委托的方法
$(‘父级’).on(‘事件名’,‘要操作的元素’,function(){
})
判断当前元素字符的长度是否大于100。
用substring(0,100) 方法 表示在 0-100个字符之间
下面的是要展示还有多少个字符

猜你喜欢

转载自blog.csdn.net/qq_44306441/article/details/89421486