摘要:<!DOCTYPE html> <html> <head> <title>腾讯微博</title> <link href="http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" re
<!DOCTYPE html>
<html>
<head>
<title>腾讯微博</title>
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style type="text/css">
body {
background-color: #ccc;
font-size: 14px;
color: #999;
}
.box {
width: 600px;
height: 200px;
background-color: #fff;
margin: 0 auto;
border-radius: 5px;
padding: 20px;
}
p {
float: left;
margin: 0;
}
.box1 {
float: left;
margin-left: 220px;
width: 150px;
height: 24px;
text-align: right;
}
.box1 span {
font-size: 16px;
font-weight: bold;
}
#txt {
width: 600px;
height: 100px;
margin-top: 5px;
border-radius: 5px;
}
.box #sp1,#sp2,#sp3,#sp4,#sp5 {
float: left;
width: 30px;
height: 32px;
line-height: 32px;
padding-left: 20px;
margin-right: 10px;
}
#sp1 {
background: url(images/a3.png) no-repeat left center;
}
#sp2{
background: url(images/a2.png) no-repeat left center;
}
#sp3 {
background: url(images/a1.png) no-repeat left center;
margin-right: 10px;
}
#sp4 {
padding-left: 5px;
}
#sp5 {
background: url(images/a4.png) no-repeat left center;
margin-left: 260px;
width: 85px;
}
</style>
<script type="text/javascript">
var txt,number,m,sp5
window.onload = function(){
txt = document.getElementById('txt');
alert (txt.value.length);
number = document.getElementById('number');
sp5 = document.getElementById('sp5');
txt.onkeyup = function aa(){
m = 140-txt.value.length;
if(m<0) {
number.style.color = 'red';
} else {
number.style.color = '#888';
}
number.innerHTML = m;
}
sp5.onclick = function (){
if(m == 140){
alert ('请输入内容');
txt.focus();
}
else if(m < 0){
alert('输入过多');
txt.focus();
} else {
alert('发布成功');
}
}
aa();
}
</script>
</head>
<body>
<div class="box">
<p>来,说说你在做什么,想什么</p>
<div class="box1"">还能输入<span id="number"></span>字</div>
<textarea id="txt"></textarea>
<span id="sp1">表情</span>
<span id="sp2">图片</span>
<span id="sp3">朋友</span>
<span id="sp4">更多<i class="fa fa-caret-down" style="float: left; margin-top: -22px; margin-left: 32px;"></i></span>
<span id="sp5"></span>
</div>
</body>
</html>



老师。这个里面带有图片了,又不能上传文件夹,所以我选择了这种方法。。然后这个js判断m==140是不生效的,请老师指教。最后请老师不要通过,这个作品是不完美的
批改老师:天蓬老师批改时间:2019-01-01 09:11:04
老师总结:.box #sp1,#sp2,#sp3,#sp4,#sp5 , 类样式之后, 不推荐这样写, 你可以考虑使用nth-child()或其它方式