Thinker_Ac
2014-12-13 12:44
demo
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
textarea {
width: 200px;
height: 20px;
}
</style>
<script type="text/javascript">
window.onload = function () {
//获取元素
var txt = document.getElementById('txt');
var total = document.getElementById('total');
txt.onfocus=function(){
this.style.height="80px";
}
txt.onblur=function(){
this.style.height="20px";
}
txt.onkeyup=function(){
var s=this.value.length;
total.innerText=s;
}
}
</script>
</head>
<body>
<textarea id="txt"></textarea>
<p>你输入了<span id="total">0</span>个字</p>
</body>
</html>
人人网评论功能
27694 学习 · 147 问题
相似问题