用jquery实现文本框已输入多少字

来源:互联网 发布:shopnc b2b2c最新源码 编辑:程序博客网 时间:2024/05/17 01:33
 
// 输入215字以内
<script type="text/javascript" language="javascript">     
   $('#memodevi').bind('keyup keypress change', function(){   
       var len =$(this).val().length;
        var remain = 215 - len;
        var tip_span = $('#infodevi');
        if( remain<0 ){
            tip_span.html("已经超过<strong style='color:red'>"+Math.abs(remain)+"</strong>字");
        }else{
            tip_span.html("还能输入<strong style='color:red'>"+Math.abs(remain)+"</strong>字");
        }
        if(remain == 215){
           tip_span.html("请输入<strong style='color:red'>"+Math.abs(remain)+"</strong>字以内");
        }
 });   
</script>
原创粉丝点击