Blogger Information
Blog 250
fans 3
comment 0
visits 321521
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS-动态获取数据
梁凯达的博客
Original
3757 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<textarea name="" id="" cols="30" rows="10" onkeyup="check(this)" maxlength="40"></textarea><span>你还可以输入<b id="bb">40</b>个字</span>
</body>
<script>
var bb = document.getElementById('bb');
var  num = bb.innerHTML;
//alert(num);
function check(obj){
	//alert(obj);
	//获取当前输入的字符串
	//alert(obj.value);
	var  msg = obj.value;
	//alert(msg.length);
	//用总数减去当前输入的字符串个数得到剩余的个数
	str = num - msg.length;
	//alert(str);
	//判断如果str小于0  我们就让他不能输入
	if (str <= 0) {
		str = 0;
	//	obj.disabled= true;
	}
	//需要将剩余的个数写入到b标签中
	bb.innerHTML = str;
}
</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post