下面是对textarea字数进行控制与显示方便以后直接调用
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.fontmany {
position: absolute;
right: 0px;
bottom: 0px;
}
.beiz {
width: 450px;
height: 340px;
position: relative;
}
</style>
</head>
<body>
<div class="beiz">
<textarea id="BZ" name="BZ" style="height: 340px; width: 450px" onkeydown="checkMaxInput(this,80)" onkeyup="checkMaxInput(this,80)" onfocus="checkMaxInput(this,80)" onblur="checkMaxInput(this,80);resetMaxmsg()"></textarea>
<div class="fontmany">
<span id="showlen">1</span>/<span id="maxlength">80</span>
</div>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
//多行文本输入框剩余字数计算
function checkMaxInput(obj, maxLen) {
if(obj == null || obj == undefined || obj == "") {
return;
}
if(maxLen == null || maxLen == undefined || maxLen == "") {
maxLen = 100;
}
var $obj = $(obj);
var newid = $obj.attr("id") + 'msg';
if(obj.value.length > maxLen) { //如果输入的字数超过了限制
obj.value = obj.value.substring(0, maxLen); //就去掉多余的字
$('#showlen').text(obj.value.length);
} else {
$('#showlen').text(obj.value.length);
}
}
</script>
</body>