JS输入框统计文字数量

$('#articleTitle').bind('input propertychange',function () {
            var a = $(this).val().length;
            if(a>30){
                var val = $(this).val().substr(0,30);
                $(this).val(val);
                $('#helpBlock2').html(30);
            }else{
                $('#helpBlock2').html(a);
            }
        });

  

<div class="row" >
                                                <!--第三排 13-->
                                                <div class="col-md-1 text-right">
                                                    标题:
                                                </div>
                                                <div class="col-md-6 list-inline">
                                                    <input class="form-control input-sm" id="articleTitle" type="text" name="title" value="" placeholder="新闻标题,最大30字"  />
                                                </div>
                                                <div style="margin-top:5px;font-size: 14px;">
                                                    <span id="helpBlock2" style="color: red;">0</span><span>/30字</span>
                                                </div>
                                            </div>

  

僵尸将臣
原文地址:https://www.cnblogs.com/sunshenggang/p/9285231.html