码迷,mamicode.com
首页 > 其他好文 > 详细

监测文本输入的字数,终极版,学习笔记

时间:2017-09-19 22:52:35      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:element   lis   ==   osi   add   学习笔记   color   start   cti   

       
///此方法可以适用多个文本框监测,如果多个文本框同时显示的话须生成多个flag已对应函数中的flag
var flag = false; function ff(str) { flag = false; document.getElementById("replycontent" + str).addEventListener("keyup", function () { if (flag == false) { document.getElementById("counttxt" + str).textContent = document.getElementById("replycontent" + str).value.length; } }); document.getElementById("replycontent" + str).addEventListener("compositionstart", function () { flag = true; }); document.getElementById("replycontent" + str).addEventListener("compositionend", function () { flag = false; document.getElementById("counttxt" + str).textContent = document.getElementById("replycontent" + str).value.length; }); }

留作学习笔记,以供以后自己使用

监测文本输入的字数,终极版,学习笔记

标签:element   lis   ==   osi   add   学习笔记   color   start   cti   

原文地址:http://www.cnblogs.com/zhhwDavidblog/p/7554385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!