1个回答
展开全部
<html>
<head>
<title>enter</title>
<script language="javascript">
function keypress1()
{
var text1=document.getElementByIdx_x("mytext1").value;
var len=15-text1.length;
var show="你还可以输入"+len+"个字";
document.getElementByIdx_x("name").innerText=show;
}
function keypress2()
{
var text1=document.getElementByIdx_x("myarea").value;
var len;//记录剩余字符串的长度
if(text1.length>=30)
{
document.getElementByIdx_x("myarea").value=text1.substr(0,30);
len=0;
}
else
{
len=30-text1.length;
}
var show="你还可以输入"+len+"个字";
document.getElementByIdx_x("pinglun").innerText=show;
}
</script>
</head>
<body>
<center>
<div style="text-align:left;">
<h>昵称:</h>
<input type="text" id="mytext1" maxlength=15 onKeyUp="keypress1()"/>
<font color="gray"><label id="name">你还可以输入15个字</label></font>
<br>
<h>评论内容:</h><br>
<textarea id="myarea" style="height:100px;width:200px;overflow-x:hidden;overflow-y:hidden" cols="10" rows="3" onKeyUp="keypress2()" onblur="keypress2()"></textarea>
<font color="gray"><label id="pinglun">你还可以输入30个字</label></font>
<div>
</center>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询