- <!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>
- <style type="text/css">
- #num{
- color:red;
- }
- </style>
- <script language="javascript" src="jquery-1.7.1.min.js"></script>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>无标题文档</title>
- </head>
- <body>
- <script language="javascript">
- function shiqu(){
- document.getElementById("status").style.borderColor="";
- }
- function jiadian(){
- document.getElementById("status").style.borderColor="#00CCFF";
- }
- function countChar(textareaName,spanName){
- if(200-document.getElementById(textareaName).value.length>=0){
- document.getElementById(spanName).innerHTML=200-document.getElementById(textareaName).value.length;
- }else{
- document.getElementById(spanName).innerHTML=0;
- }
- if(document.getElementById(textareaName).value.length>=200){
- document.getElementById("num").style.display="";
- document.getElementById("bt").disabled=true;
- return false;
- }else{
- document.getElementById("num").style.display="none";
- document.getElementById("bt").disabled=false;
- }
- }
- </script>
- 还可以输入<span id="counter">200</span>字<br>
- <form>
- <textarea id="status" name="status" cols="50" rows="10" onkeydown='countChar("status","counter");' onkeyup="countChar('status','counter');" onfocus="jiadian();" onblur="shiqu();">
- </textarea>
- <input type="button" value="发表" id="bt" />
- </form>
- <div id="num" style="display:none;">字数超过了</div>
- </body>
- </html>
js文本域限制
最新推荐文章于 2023-04-13 18:15:30 发布