$(function () {
/**
* 字数限制
*/
$('[max-word-length]').each(function () {
var area = $(this);
var length = area.attr("max-word-length");
area.bind('input propertychange', function() {
var val = $(this).val();
if (val && val.length>length){
$(this).val( val.toString().substring(0,length) );
}
});
});
});
标签内使用max-word-length="10" ,属性即可,当前字数限制是10字,可以改变 :
<div style="margin: 10px;">
<textarea name="reason" cols="50" rows="5" placeholder="10字以内" max-word-length="10"></textarea>
</div>