javascript函数-计算字符个数

代码:

<style type="text/css">
p{
	float:left;
}
body{
	width:600px;
	margin:	auto;
	font-family:"微软雅黑 Light", Consolas;
	font-size:20px;
	border:2px solid #0F6;
}
textarea{
	margin:15px;
}
</style>
</head>
<body>
<div>
<p>&nbsp;&nbsp;您还能输入</p>
<p id="count" style="color:#F99">150</p>
<p>个字符的祝福信息,发送给你最想祝福的人吧!</p>
</div>
<textarea cols="70" rows="4" name='string' onkeyup="charCount(this,'count')"></textarea>
<script language="javascript">
function charCount(obj,show){
	var  str = obj.value;
	var count = str.length;
	document.getElementById(show).innerHTML = 150 - count;
}
</script>
</body>
</html>

图片:

猜你喜欢

转载自blog.csdn.net/Tjhfsghbjknjdy/article/details/84978110
今日推荐