<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery.min.js"></script>
</head>
<body>
<div class="container">
<input id="abc" value="你好"><span id="wordCountShow"></span>
</div>
<script>
$.fn.extend({
wordCount: function (maxLength, wordWrapper) {
var self = this;
$(self).attr("maxlength", maxLength);
showWordCount();
$(this).on("input propertychange", showWordCount);
function showWordCount() {
curLength = $(self).val().length;
var leaveCount = maxLength - curLength;
wordWrapper.text(leaveCount + "/" + maxLength);
}
}
})
$(function () {
$("#abc").wordCount(10, $("#wordCountShow"));
})
</script>
</body>
</html>
简易的输入框字数计数 Jquery组件
最新推荐文章于 2021-11-11 22:16:17 发布