夏夜,天上缀满了闪闪发光的星星,像细碎的流沙铺成的银河斜躺在青色的天宇上。大地已经沉睡了。我任了性,纵容思念开成一片海,定格成回忆里抹不去的风景。太阳把大海映红了,好像得大海披上了一层红纱。
本文实例讲述了jQuery实现简易的输入框字数计数功能。分享给大家供大家参考,具体如下:
运行效果图如下:
具体代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="jquery-1.7.2.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>
PS:这里再为大家提供几款带有字数统计功能的在线工具供大家参考使用:
在线字数统计工具:
http://tools.haodaima.com/code/zishutongji
在线文本美化排版工具:
http://tools.haodaima.com/aideddesign/txt_paiban
在线自动排版与转换工具:
http://tools.haodaima.com/aideddesign/txt_beaut
希望本文所述对大家jQuery程序设计有所帮助。
以上就是jQuery实现简易的输入框字数计数功能示例。领悟就是1条荆棘从生的路,你只有用刻苦做武器,勤奋做盾牌,才能走得出去。更多关于jQuery实现简易的输入框字数计数功能示例请关注haodaima.com其它相关文章!




