摘要:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<style>
* {
margin: 0;
padding: 0;
}
body {
font-size: 14px
}
.box {
width: 550px;
height: 200px;
border: 10px solid pink;
margin: 10px auto;
}
#img1 {
float: left;
}
.box1 {
float: left;
margin-left: 150px;
text-align: right;
width: 200px;
height: 24px;
color: #888
}
.box1 span {
font-size: 16px;
font-weight: bold;
}
textarea {
width: 530px;
height: 130px;
border: 1px solid #ccc;
margin: 2px 10px;
}
ul #img_1,
#img_2,
#img_3,
#img_4,
#img_5,
#tx1 {
float: left;
height: 32px;
width: 30px;
line-height: 32px;
padding-left: 24px;
font-size: 12px
}
#img_1 {
background: url(images/an5.png) no-repeat left center;
}
#img_2 {
background: url(images/an4.png) no-repeat left center;
}
#img_3 {
background: url(images/an3.png) no-repeat left center;
}
#img_4 {
background: url(images/an2.png) no-repeat left center;
}
#img_5 {
background: url(images/an1.png) no-repeat left center;
width: 50px;
}
#tx1 {
margin-left: 100px;
color: #888
}
#bt {
float: left;
width: 80px;
height: 30px;
border: none;
background: #ffc09f;
color: #fff;
border-radius: 5px;
margin-left: 15px;
}
</style>
<script>
var text,number
var m=140;
//在页面或图像加载完成后立即发生。
window.onload=function (){
text=document.getElementById('text')
number=document.getElementById('number')
bt=document.getElementById('bt')
text.onkeyup=function aa(){
m=140-text.value.length
if(m<0){
number.style.color="red"
}else{
number.style.color="#888"
}
number.innerHTML=m;
}
bt.onclick=function (){
if(m==140){
alert('请先输入微博再发布')
text.focus() //返回text
}else if(m<0){
alert('微博文字过长,不可以发布')
text.focus()
}else{
alert('微博发布成功')
}
}
aa()
}
</script>
<title>微博输入框</title>
</head>
<body>
<div class="box">
<img src="images/12.png" alt="" id="img1">
<div class="box1">还可以输入<span id="number"></span>字</div>
<textarea name="" id="text" cols="30" rows="10"></textarea>
<ul>
<span id="img_1">表情</span>
<span id="img_2">图片</span>
<span id="img_3">视频</span>
<span id="img_4">话题</span>
<span id="img_5">长微博</span>
<span id="tx1">公开</span>
<input type="button" value="发布" id="bt">
</ul>
</div>
</body>
</html>
批改老师:灭绝师太批改时间:2019-02-22 17:35:41
老师总结:完成的不错,就是下次的案例可以跳脱出老师上课案例呦!