js自动统计文本框内已输入字数个数

2个月前 (06-04 17:29)阅读回复0
大陆
大陆
  • 管理员
  • 发消息
  • 注册排名1
  • 经验值5294
  • 级别管理员
  • 主题1058
  • 回复2
楼主

这是一款文本框限制文字输入总数js特效,在旁边即时显示当前已输入的文字个数,根据自己的需求来自定义数量即可。

<a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr>
<!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。-->
<script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script>
<script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script>
<textarea id="b" rows="4" cols="20" ></textarea>
<div><span id="a">已输入字符: </span><input type="button" value="OK" onclick="cha()"></div>
<script language="javascript">
<!--
var ppl=70//每条长
var maxl=200//总长
document.onkeydown=function(){
   var s=document.getElementById("b").value.length +1;
   if(s>maxl)document.getElementById("b").value=document.getElementById("b").value.substr(0,maxl-1)
   else document.getElementById("a").innerHTML="已输入:"+s+"/"+maxl+" 字符"
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
function cha(){
var txt=document.getElementById("b").value,tl=txt.length;
var txtArray=[],k=(tl/ppl<=1)?1:Math.ceil(tl/ppl);
for (var i=0;i<k;i++){
txtArray[i]=txt.substr(i*ppl,ppl);
alert(txtArray[i]) ;
}
document.getElementById("b").value=""
document.getElementById("a").innerHTML="已输入字符: "
}//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)
//-->
</script>


0
0
收藏0

本文来自武鸣人网站,转载请注明出处

本文地址:https://www.wuming.ren/a/1123.html

回帖

js自动统计文本框内已输入字数个数 期待您的回复!

取消
载入表情清单……
载入颜色清单……
插入网络图片

取消确定

图片上传中
编辑器信息
提示信息