Html
    Css
    Js
1
2
3
4
5
6
<h2></h2>
<div id="div_editor">
<textarea id="txt_content" rows="2" cols="10"></textarea>
<div class="d-last">140</div>
</div>
<input type="button" id="btn_submit" value="">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
h4 {
color:#B1B1B1;
font-weight:100;
font-size:14px;
}
#div_editor {
width:400px;
border:1px solid #A9A9A9;
}
#div_editor textarea {
border:0px;
width:398px;
height:45px;
outline:0px;
resize:none;
}
#div_editor div.d-last {
text-align:right;
font-size:10px;
color:#B1B1B1;
display:none;
}
#btn_submit {
color:white;
background-color:#8AC328;
width:80px;
height:25px;
border:1px solid #9CC868;
margin:1px;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$(function() {
$("#div_editor textarea").focus(function() {
$(this).css("height", "60px");
$("#div_editor div.d-last").show();
$("#div_editor").css("borderColor", "#B4E6FA");
}).blur(function() {
$(this).css("height", "45px");
$("#div_editor div.d-last").hide();
$("#div_editor").css("borderColor", "#A9A9A9");
}).keyup(function() {
var c = $(this).val();
if (c.length > 140) {
c = c.substr(0, 140);
$(this).val(c);
}
var last = 140 - c.length;
$("#div_editor div.d-last").text("" + last + "");
})
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
↑上面代码改变,会自动显示代码结果 jQuery调用版本:1.11.3
 立即下载

输入框输入字数限制

当用户想在一个输入框中输入一下字,但是不能输太多,这时候就要有字数限制,但是还可以时时显示还可输入多少字

3
      ??0
      2017/7/22 18:03:45

      还有那个button按钮的位置固定住了呢,不随着高度的变化改变位置呢

      回复
      ??0
      2017/7/22 18:01:58
      为什么我做的她那个外面的div的高度不跟着里面textarea的高度变化呢 回复
      化雪,情飞翔0
      2017/7/19 17:11:26
      css js html 代码放在一起了,没有分开,因为第一次上传 回复