<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery text文本框限制字数或文本框提示字数</title>
<script type="text/javascript">
function checkLength(which) {
var maxChars = 10; //
if(which.value.length > maxChars){
alert("您出入的字数超多限制!");
// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
which.value = which.value.substring(0,maxChars);
return false;
}else{
var curr = maxChars - which.value.length; //250 减去 当前输入的
document.getElementById("sy").innerHTML = curr.toString();
return true;
}
}
</script>
</head>
<body>
<form name="" id="" action="" class="Form">
<textarea id="TextArea1" οnkeyup="checkLength(this);"
style="width:600px;height:84px"></textarea><br/><br />
<button>注册登录</button>
<span class="wordage">剩余字数:<span id="sy" style="color:Red;">10</span></span>
</form>
</body>
</html>
文本框限制字数提示
最新推荐文章于 2024-04-30 08:34:04 发布