亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

微博輸入實(shí)例java+css

original 2018-12-30 13:32:32 245
abstrait:<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>微博輸入布局</title> <style type="text/css"> body{background:#5DA8
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>微博輸入布局</title>
	<style type="text/css">
body{background:#5DA8D3;font-size:12px;}
.box{width:600px;height:170px;border:1px solid #ccc;background:#fff;margin:10px auto;}
img{float:left;margin:5px 8px;}
.wz{float:left;color:#808080;margin-left:315px;margin-top:12px;}
#num{font-weight:bold;}
#area{width:570px;height:80px;border:1px solid #ccc;margin:3px 10px;}
.box #no1,#no2,#no3,#no4,#no5,#no6,#no7{float:left;width:30px;height:32px;line-height:32px;color:#000;padding-left:26px;}
#no1{background:url(img/wb/01.png) no-repeat left center;margin-left:8px;}
#no2{background:url(img/wb/02.png) no-repeat left center;}
#no3{background:url(img/wb/03.png) no-repeat left center;}
#no4{background:url(img/wb/04.png) no-repeat left center;}
#no5{background:url(img/wb/05.png) no-repeat left center;width:48px;padding-left:30;}
#no6{background:url(img/wb/06.png) no-repeat left center;margin-left:15px;}
#no7{margin-left:70px;}
input{border:1px solid #ccc;width:82px;height:30px;background:#FF8140;color:#fff;}

</style>

<script type="text/javascript">
        var area,num,m//area是文本域輸入的字?jǐn)?shù),num是右上方顯示的字?jǐn)?shù),m是輸入的字?jǐn)?shù)
        window.onload=function(){
        	area=document.getElementById('area')//獲取這三個(gè)ID
        	num=document.getElementById('num')
        	bt=document.getElementById('bt')
        	area.onkeyup=function aa(){//通過(guò)文本域的鍵盤(pán)彈起來(lái)判斷
        		m=140-area.value.length//輸入的字?jǐn)?shù)m等于總字?jǐn)?shù)140減去文本域已經(jīng)輸入字?jǐn)?shù)的長(zhǎng)度
        		if(m<0){//小于零,就是負(fù)數(shù),證明輸入超過(guò)了140個(gè)字
        			num.style.color="red"//字體顏色變紅
        		}else{//不小于零,證明字?jǐn)?shù)沒(méi)有超過(guò)140個(gè)字
        			num.style.color="#888"//字體顏色正常
        		}
        		num.innerHTML=m//把獲取到的數(shù)直接輸出到num位置
        	}

        	bt.onclick=function(){//發(fā)布按鈕點(diǎn)擊事件來(lái)判斷
        		if(m==140){//m等于140,證明輸入字?jǐn)?shù)為0
        			alert("您還沒(méi)有輸入")
        			area.focus()//文本域獲取焦點(diǎn),更好的用戶體驗(yàn)
        		}else if(m<0){//m小于0,就是負(fù)數(shù),證明字?jǐn)?shù)大于140個(gè)字
        			alert("字?jǐn)?shù)太多,不可以發(fā)布")
        			area.focus()/文本域獲取焦點(diǎn)
        		}else{//字?jǐn)?shù)正常,可以發(fā)布
        			alert("發(fā)布成功")
        		}
        	}
        	aa()//新手注意:記得調(diào)用函數(shù)
        }
	</script>

</head>
<body>
	<div class="box">
<img src="img/wb/00.png">
<div class="wz">已輸入<span id="num"></span>字</div>
<textarea id="area"></textarea>
<span id="no1">表情</span>
<span id="no2">圖片</span>
<span id="no3">視頻</span>
<span id="no4">話題</span>
<span id="no5">頭條文章</span>
<span id="no6"></span>
<span id="no7">公開(kāi)</span>
<input type="button" id="bt" value="發(fā)布">
</div>
	
</body>
</html>

其中的java部分對(duì)我來(lái)說(shuō)還是有點(diǎn)難度,爭(zhēng)取今天再多做兩遍。

Professeur correcteur:天蓬老師Temps de correction:2018-12-30 13:37:20
Résumé du professeur:window.onload=function(){...}, 這個(gè)onload事件,以后實(shí)戰(zhàn)中可以用DOMContentLoaded 這個(gè)事件來(lái)替換

Notes de version

Entrées populaires