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

微博輸入字數(shù)

原創(chuàng) 2019-02-15 15:14:42 207
摘要:<!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">

<title>微博輸入字數(shù)</title>

<style>

*{margin:0;padding: 0;}

.box{width: 600px;height: 160px;border: 10px solid orange;margin: 0 auto;padding: 10px;}

img{float: left;}

.box1{float: left;margin-left: 255px;width: 150px;height: 24px;text-align: right;font-size: 14px;color: #888;}

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

#text{width: 600px;height: 100px;border: 1px solid #888;margin-top: 5px;}

.box #sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float:left;width: 39px;height: 32px;line-height: 32px;padding-left: 20px;font-size: 10px;}

#sp6{margin-left: 150px;margin-right: 15px;color:#888;}

#bt{float: left;width: 80px;height: 30px;border: none;background: #ffc09f;color: #fff;border-radius: 4px;}

</style>

</head>

<body>

<script>

var text,number,m,bt

window.onload=function(){

text=document.getElementById('text')

number=document.getElementById('number')

bt=document.getElementById('bt')

text.onkeyup=function keyup(){

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內(nèi)部

}else if(m<0){

alert('字數(shù)過多')

text.focus()

}else{

alert('發(fā)布成功')

}

}

}

</script>

<div class="box">

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

<div class="box1">還可以輸入<span id='number'>140</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">    

</div>

</body>

</html>

總結:

1創(chuàng)建四個變量存儲數(shù)據(jù):text(輸入框),number(span提示),m(或許輸入框內(nèi)字符串長度),bt(獲取button按鈕)

2點擊鍵盤判斷字數(shù),如果鍵盤字數(shù)過多輸出紅色,如果在140以內(nèi)輸出灰色

3點擊button判斷


批改老師:韋小寶批改時間:2019-02-15 15:25:45
老師總結:寫的很不錯 總結的也很到位 沒事可以多寫點這種小案例 可以把之前學習的布局 以及js都練習練習!

發(fā)佈手記

熱門詞條