input框输入限制

来源:互联网 发布:php 记录日志 编辑:程序博客网 时间:2024/05/17 07:29
效果图:

html代码:


<!doctype html><html><script>function check(obj,id01,id02,maxLength){var textarea = document.getElementById('Context');if(textarea.value.length > maxLength){alert("Input can not beyond 10  character !!!");textarea.value = textarea.value.substring(0,maxLength);}else{id01.value = textarea.value.length;id02.value = maxLength-id01.value;}}    </script><head><title>限制文本框中的输入字数</title></head><body><form name="myForm" method="post">标题:<input type="text" name="textTitle" size="30" maxlength="8">(限输入8个文字)<br>内容:<textarea rows="10" cols="30" id="Context"name="Context" onKeyDown="check(this,textCount,textCount2,10)" onKeyUp="check(this,textCount,textCount2,10)"   oncut="return false;"onpaste="return false;"></textarea><br>(限输入10个文字)<br>您已经输入了<input type="text" id="textCount" size="3" readonly>个字<br>            还能继续输入<input type="text" id="textCount2" size="3" readonly>个字</form></body></html>


1 0
原创粉丝点击