zoukankan      html  css  js  c++  java
  • 输入框字数控制

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    </head>
    
    <body>
    
    
    
        <input type="text" onkeyup="checkLength(this);"/><span id="words" style="color:Red;">200</span>
        <input type="text" onkeyup="checkLength(this);"/><span id="wordss" style="color:Red;">200</span>
        <input type="text" onkeyup="checkLen(this);"/><span id="word" style="color:Red;">50</span>
    <script type="text/javascript">
    function checkLength(words) {
    	var maxChars = 200; //
    	if(words.value.length > maxChars){
    		alert("您出入的字数超多限制!");
    		// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
    		words.value = words.value.substring(0,maxChars);
    		return false;
    	}else{
    		var curr = maxChars - words.value.length; 
    		document.getElementById("words").innerHTML = curr.toString();
    		document.getElementById("wordss").innerHTML = curr.toString();
    		return true;
    	}
    }
    
    function checkLen(words) {
    	var minChars = 50; //
    	if(words.value.length > minChars){
    		alert("您出入的字数超多限制!");
    		// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
    		words.value = words.value.substring(0,minChars);
    		return false;
    	}else{
    		var curr = minChars - words.value.length; 
    		document.getElementById("word").innerHTML = curr.toString();
    		return true;
    	}
    }
    </script>
    </body>
    
    </html>
    

      

  • 相关阅读:
    mupdf arm 交叉编译记录
    lua的closure创建和使用
    Lua函数执行流程及函数延续点问题的研究
    boost::statechart研究报告
    lambda,std::function, 函数对象,bind的使用备忘
    将博客搬至CSDN
    Impala的分布式查询
    轻量级文本搜索引擎的后台设计、实现与优化
    1 producer — n consumers 模型 实现
    1001. A+B Format (20)
  • 原文地址:https://www.cnblogs.com/hellman/p/4078604.html
Copyright © 2011-2022 走看看