JS统计还可以输入多少字数,用于向输入者提示信息
2个回答
展开全部
<meta name="description" content="JS限制textarea输入框输入字数" /
<title</title
<SCRIPT language="javascript"<!--function checktext(text){allValid = true;
for (i = 0; i < text.length; i++){if (text.charAt(i) != " "){allValid = false;break;}}return allValid;}function gbcount(message,total,used,remain){var max;max = total.value;
if (message.value.length max) {
message.value = message.value.substring(0,max);
used.value = max;
remain.value = 0;
<!-- alert("留言不能超过 200 个字!");--
alert("不能超过"+total.value+"个字!");}else {used.value = message.value.length;
remain.value = max - used.value;}}--</script
<style type="text/css"<!--* {padding:0; margin:0;}
body, html {text-align:left; font-size:12px; line-height:150%; margin:0 auto; background:#fff; padding-top:20px;}
fieldset {padding:10px; width:550px; margin:0 auto;}
legend {font-size:14px; font-weight:bold;}
.inputtext {border:none; background:#fff;}--</style</head<body<form action="SaveData.asp" method="post"
<fieldset<legend请输入内容</legend
<textarea name="Memo" rows="10" wrap=PHYSICAL cols="75" onKeyDown="gbcount(this.form.Memo,this.form.total,this.form.used,this.form.remain);" onKeyUp="gbcount(this.form.Memo,this.form.total,this.form.used,this.form.remain);"</textarea
<input disabled maxLength="4" name="total" size="3" value="10" class="inputtext"已用字数:<input disabled maxLength="4" name="used" size="3" value="0" class="inputtext"剩余字数:<input disabled maxLength="4" name="remain" size="3" value="10" class="inputtext"</td</p</fieldset</form</body</html
展开全部
<input type='text' id='num' name='tel' value='12345' onKeyUp="showLen(this);"> <span id="span">已输入XX位</span>
<script type="text/javascript">
showLen(document.getElementById("num"));
function showLen(obj){
document.getElementById('span').innerHTML = '已输入'+ (obj.value.length) +'位';
}
</script>
可以看看这个代码
<script type="text/javascript">
showLen(document.getElementById("num"));
function showLen(obj){
document.getElementById('span').innerHTML = '已输入'+ (obj.value.length) +'位';
}
</script>
可以看看这个代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询