JS 限制input框的输入字数,并提示可输入字数
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>限制文件字数字</title>
</head>
<body>
<span class="span">备注信息</br><span id="stay" style="display: none"> 您还可以输入:<span id="txtCount"></span>个字符的描述信息</span></span>
</br><input id="Remark_information" name="Remark_information" type="text">
<script>
var lim=new limit();
lim.txtNote=document.getElementById("Remark_information");
lim.txtLimit=document.getElementById("txtCount");
lim.limitCount=80;
lim.init();
function limit(){
var txtNote;//文本框
var txtLimit;//提示字数的input
var limitCount;//限制的字数
var txtlength;//到达限制时,字符串的长度
this.init=function(){
txtNote=this.txtNote;
txtLimit=this.txtLimit;
limitCount=this.limitCount;
txtNote.oninput=function(){wordsLimit()};txtNote.oninput=function(){wordsLimit()};
txtLimit.innerText=limitCount;
};
function wordsLimit(){
var noteCount=txtNote.value.length;
var InPut=document.getElementById("Remark_information").value.length;
if(InPut<1){
document.getElementById("stay").style.display="none";
return
}
if(InPut>=1){
document.getElementById("stay").style.display="inline";
document.getElementById("stay").style.color="green";
}
if(InPut>70){
document.getElementById("stay").style.color="red";
}
if(noteCount>limitCount){
txtNote.value=txtNote.value.substring(0,limitCount);
txtLimit.innerText=0;
}else{
txtLimit.innerText=limitCount-noteCount;
}
txtlength=txtNote.value.length;//记录每次输入后的长度
}
}
</script>
</body>
JS 限制input框的输入字数,并提示可输入字数的更多相关文章
- js控制input框输入数字时,累计求和
input框输入数字时,自动开始计算累加 <div class="form-group"> <label for="inputPassword3&quo ...
- js 动态控制 input 框 的只读属性
需求: 当下拉框的值为06即Voucher时, 文本框才可输入, 其他情况均为置灰不可录入状态. 问题: 设置input框的只读属性写成了readonly="true" 尼玛,坑死 ...
- php页面输出时,js设置input框的选中值
/* 设置表单的值 */ function setValue(name, value) { var first = name.substr(0, 1), input, i = 0, val; if ( ...
- js控制 input框中输入数字时,累计求和
$('.cc input').bind('input propertychange', function(){ var total = 0; $("input").each(fun ...
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
<script language="JavaScript" type="text/javascript"> function clearNoNum( ...
- Js限制Input框只能输入数字
<input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" /> <input ...
- js复制input 框中的值
function copy(){ var Url2=document.getElementById("copyValue"); Url2.select(); document.ex ...
- js对input框的可编辑属性设置
添加disabled属性 $('#areaSelect').attr("disabled",true); $('#areaSelect').attr("disabled& ...
- 关于input框仿百度/google自动提示的方法
引入jquery-autocomplete文件 链接:https://pan.baidu.com/s/1hW0XBYH8ZgJgMSY1Ce6Pig 密码:tv5b $(function() { $( ...
随机推荐
- -webkit-appearance: none; 去除浏览器默认样式
-webkit-appearance: none; 去除浏览器默认样式
- prevent阻止标签默认行为&stop阻止事件冒泡
<form id="vm" v-on:submit.prevent="register"> 1.prevent是preventDefault,阻止标 ...
- 对于开启tomcat后无法登陆index.xml的新解决方法
首先这个问题是针对tomcat路径什么的都正确,但是就是无法登陆index.xml 如上图,之前忘了写<packaging>war</packaging>所以无法登陆index ...
- The socket is closed!
关闭mongodb /usr/local/app/mongidb//bin/mongod --shutdown --dbpath /usr/local/data/mongo/data/ 然 ...
- SQL更新字段内容部分值
UPDATE att_allSET attachment = REPLACE(attachment, 'pw/', '')WHERE (attachment LIKE 'pw/%')
- 训练1-P
一个矩形的面积为S,已知该矩形的边长都是整数,求所有满足条件的矩形中,周长的最小值. 例如:S = 24,那么有{1 24} {2 12} {3 8} {4 6}这4种矩形,其中{4 6}的周长最小, ...
- Centos上Mysql5.6的安装
安装步骤: (1)查看Centos是否自带mysql :rpm -qa | grep mysql (2)将原有卸载 rpm -e --nodeps mysql-libs-5.1.73-5.el ...
- phpunit使用
phpunit使用 标签(空格分隔): php 现在是凌晨 3 点.我们怎样才能知道自己的代码依然在工作呢? Web 应用程序是 24x7 不间断运行的,因此我的程序是否还在运行这个问题会在晚上一直困 ...
- (0)资料官网【从零开始学Spring Boot】
Spring Boot官网:http://projects.spring.io/spring-boot/ Eclipse官网:http://www.eclipse.org/ Maven官网:http: ...
- springMVC3.0(文件上传,@RequestMapping加參数,@SessionAttributes,@ModelAttribute,转发,重定向,数值获取,传參,ajax,拦截器)
1.项目包结构例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsiz ...