29 lines
684 B
JavaScript
29 lines
684 B
JavaScript
$(document).ready(function() {
|
|
setTextAreaLimit();
|
|
|
|
function setTextAreaLimit() {
|
|
$.fn.extend({
|
|
limiter: function(limit, elem) {
|
|
$('textarea').on("keyup focus show", function() {
|
|
setCount(this, elem);
|
|
});
|
|
|
|
function setCount(src, elem) {
|
|
if(src !== undefined) {
|
|
var chars = src.value.length;
|
|
if (chars > limit) {
|
|
src.value = src.value.substr(0, limit);
|
|
chars = limit;
|
|
}
|
|
elem.html(limit - chars);
|
|
}
|
|
}
|
|
setCount($(this)[0], elem);
|
|
}
|
|
});
|
|
|
|
var elem = $(".chars span");
|
|
$('textarea').limiter(1000, elem);
|
|
}
|
|
});
|