微博留言字数输入限制

Original 2018-12-25 22:06:32 541
abstract:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>微博留言</title><style>*{margin:0;padding:0;}.box{width: 600px;height: 200px;margin:0 auto;borde

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>微博留言</title>

<style>

*{margin:0;padding:0;}

.box{width: 600px;height: 200px;margin:0 auto;border:5px solid pink;border-radius: 5px;padding: 10px}

.top img{float: left;}

.top p{display: block;width: 50%;float: right;text-align: right;font-size: 12px;line-height: 24px;color:#888}

.top span{font-size: 16px;font-weight: bold;}

#text{width: 100%;height: 145px;border-radius: 5px;margin-top:5px;border-color:#ccc;}

#sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float: left;width: 50px;text-align: right;height: 24px;line-height: 24px;font-size: 12px;margin-left: 5px}

#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: 60px;}

#sp6{margin-right: 15px}

.button{float: right;}

#button{border: none;height: 24px;background: #ffc09f;color:white;width: 60px;border-radius: 3px}

</style>

<script>

var text,number,m

window.onload=function(){

text=document.getElementById('text')

number=document.getElementById('number')

button=document.getElementById('button')

text.onkeyup=function aa(){

m=140-text.value.length

if(m<0){

number.style.color="red"

}else{

number.style.color="#888"

}

number.innerHTML=m

}

button.onclick=function(){

if(m==140){

alert("你还没有输入!");

text.focus()

}else if(m>130){

alert("字数少于10,不可发布!")

text.focus()

}else if(m<0){

alert("字数太多,不可发布!")

text.focus()

}else{

alert("发布成功!")

}

}

aa()

}

</script>

</head>

<body>

<div>

<div>

<img src="images/12.png" alt="">

<p>还可输入<span id="number"></span>字</p>

</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>

<div>

<span id="sp6">公开</span>

<input type="button" value="发布" id="button">

</div>

</div>

</body>

</html>


Correcting teacher:灭绝师太Correction time:2018-12-26 09:20:58
Teacher's summary:源码跟老师源代码一摸一样啊,不应该,aa()这个函数不需要函数名,老师语法错误,你也跟着,下次不要这样了,代码要有自己的思路

Release Notes

Popular Entries