摘要:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>微博输入</title> <style> body{} *{margin: 0px;p
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>微博输入</title>
<style>
body{}
*{margin: 0px;padding: 0px;}
#cont{border: 10px solid pink;width: 600px;height:180px;margin: 10px auto;padding: 10px;}
img{float: left;}
#right{font-size: 14px;color: #888; float: right;padding-right: 10px; height: 24px;line-height: 24px;}
#right span{font-size: 14px;color: #888;font-weight: bold;}
#text{margin-top: 5px;width: 600px;height: 120px;resize: none;border: 1px solid #888;}
#sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float: left;width: 35px;height: 32px;line-height: 32px;padding-left: 26px;}
#sp1{background: url(images/an5.png) no-repeat left center;}
#sp2{background: url(images/an4.png) no-repeat left center;}
#sp3{background: url(images/an3.png) no-repeat left center;}
#sp4{background: url(images/an2.png) no-repeat left center;}
#sp5{background: url(images/an1.png) no-repeat left center;width: 50px;}
#sp6{margin-left: 120px;margin-right: 15px;color: #888;font-size: 13px;}
#bt{border-style: none;width: 80px;height: 32px;background-color: #FFC09F;border-radius:5px;color: #fff;}
</style>
<script>
var text,number,m;
window.onload=function(){
text=document.getElementById('text')
number=document.getElementById('number')
bt=document.getElementById('bt')
text.onkeyup=function(){
m=140-text.value.length //获取到文本140减去文本字长度
if (m<0){
number.style.color="red"
}else{
number.style.color="#888"
}
number.innerHTML=m;
}
bt.onclick=function(){
if (m==undefined || m==140){
alert("你还没有输入内容");
text.focus()
}else if(m<0){
alert("字数太多,不可以发布");
text.focus()
}else{
alert("发布成功"+m)
}
}
}
</script>
</head>
<body>
<div id="cont">
<img src="images/12.png" alt="">
<div id="right">还可以输入<span id="number"></span>字</div>
<textarea id="text"></textarea>
<span id="sp1">表情</span>
<span id="sp2">图片</span>
<span id="sp3">视频</span>
<span id="sp4">话题</span>
<span id="sp5">长微博</span>
<span id="sp6">公开</span>
<button id="bt">发布</button>
</div>
</body>
</html>我稍微改了一下和视频中的不太一样!
首先创建变量然后通过html获取到元素然后赋值给变量。规定输入字数就是字数的上限值减去文本框内文本长度,把结果赋值给变量。然后把这个变量的值通过innerHTML传递给span!
不太会总结不过知道这么做可以实现这个功能!
可以的话希望老师帮忙总结一下!
批改老师:韦小宝批改时间:2019-01-05 09:13:53
老师总结:你这上面的不就是总结嘛!写的很不错!任何的学习过程中都是要这样去按照自己的思路去修改,或者去创新!