HTML :
<input id="reasonRemark" type="text" class="reasonRemark" placeholder="最多128字"/>
<span><span class="textCount">0</span>/128</span>
<p class="textCountTip" style="color: red"></p>
JS:
// 原因输入字符显示还剩多少
$('.reasonRemark').bind('input propertychange',function(){
var nowLen = $(this).val().length; // 现在的长度
if(nowLen < 128){
$('.textCount').css("color","blue");
$('.textCount').text(nowLen);
$('.textCountTip').text("");
}else {
$('.textCount').css("color","red");
$('.textCount').text(nowLen);
$('.textCountTip').text("超过字数限制,请保持在128个以内!");
}
});
页面:
初始页面:

正常输入:

超过限制:

来源:oschina
链接:https://my.oschina.net/zjllovecode/blog/4304301