我想向用户显示他们要输入多少个允许的字符,我想将其放在文本区域的右下方,在新行之后;无论如何,在textarea改变之后刷新它。我只需要帮助将它放在上述位置。
答案 0 :(得分:1)
$ nginx -v
nginx version: nginx/1.10.2
$ php -version
PHP 5.6.29 (cli) (built: Dec 9 2016 07:03:56)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

function countChar(val){
var len = val.value.length;
if (len >= 50) {
val.value = val.value.substring(0, 50);
} else {
$('#charNum').text(50 - len);
}
};

.main{
position: relative;
display: inline-block;
}
.main textarea{
height: 100px;
width: 100px;
resize: none;
}
.main span{
color: coral;
position: absolute;
bottom: 5px;
right: 10px;
}

答案 1 :(得分:0)
可以用这样的东西来实现。
function count(){
document.getElementById('textarea').onkeyup = function () {
document.getElementById('count').innerHTML = this.value.length;
};
}
.main{
position: relative;
display: inline-block;
}
.main textarea{
height: 100px;
width: 200px;
resize: none;
}
.main span{
color: coral;
position: absolute;
bottom: 5px;
right: 5px;
}
<div class="main">
<textarea id="textarea" onclick="count()"></textarea>
<span id="count">0</span>
</div>
答案 2 :(得分:0)
你可以这样做:
<div class="form-block">
<textarea></textarea>
<div class="label"></div>
</div>
在CSS中:
.form-block {
position: relative;
}
.label {
bottom: 5px;
position: absolute;
right: 5px;
}