abstrak:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml&quo
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>weibo輸入</title>
<style type="text/css">
body{ font-size:12px;}
.box{
margin: auto;
height: 160px;
width: 600px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #FF80FF;
border-right-color: #FF80FF;
border-bottom-color: #FF80FF;
border-left-color: #FF80FF;
padding: 10px;
}
img{
float: left;
}
.box1{
float: left;
height: 24px;
width: 150px;
margin-left: 255px;
text-align: right;
font-size: 9px;
color: #888;
}
.box1 span{
font-size: 16px;
font-weight: bold;
}
#text{
height: 100px;
width: 600px;
margin-top: 5px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
.box #sp1,#sp2,#sp1,#sp3,#sp4,#sp5,#sp6{
float: left;
height: 32px;
width: 30px;
padding-left: 26px;
line-height: 32px;
}
#sp1{
background-image: url(images/an5.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp2{
background-image: url(images/an4.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp3{
background-image: url(images/an3.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp4{
background-image: url(images/an2.png);
background-repeat: no-repeat;
background-position: left center;
}
#sp5{
background-image: url(images/an1.png);
background-repeat: no-repeat;
background-position: left center;
width: 40px;
}
#sp6{
margin-right: 15px;
margin-left: 150px;
color: #888;
}
#bt{
float: left;
height: 30px;
width: 80px;
background-color: #ffc09f;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none;
border-top-color: #fff;
border-right-color: #fff;
border-bottom-color: #fff;
border-left-color: #fff;
border-radius: 5px;
margin-top: 2px;
}
</style>
<script>
var text,number,m
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()}else if(m<0){alert("字?jǐn)?shù)太多,不可以發(fā)布")
text.focus()}
else{alert("發(fā)布成功")}
}
aa()
}
</script>
</head>
<body>
<div class="box">
<img src="images/12.png">
<div class="box1">還可以輸入<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>
<input type="button" value="發(fā)布" id="bt">
</body>
</html>
<!--CSS總結(jié)
border-radius: 圓角
JS總結(jié)
getElementById() 返回帶有指定ID的元素
innerHTML 寫入到HTML元素
windown.onload 瀏覽器已完成頁面的加載
if...else if...else 用來選擇代碼塊之一來執(zhí)行
-->
Guru membetulkan:天蓬老師Masa pembetulan:2018-12-30 13:31:42
Rumusan guru:如果覺得getElementById() 等這些方法太麻煩,不妨用: querySelector()等,再方便