微博输入字数实例2

原创 2018-11-15 17:10:01 238
摘要:<!DOCTYPE html><html><head> <title>微博论坛输入框实例</title> <link rel="stylesheet" type="text/css" href="css/font-awesome-4.7.0/css/font-awesome.min.

<!DOCTYPE html>

<html>

<head>

<title>微博论坛输入框实例</title>

<link rel="stylesheet" type="text/css" href="css/font-awesome-4.7.0/css/font-awesome.min.css">

<style type="text/css">

body{font-size: 1px;}

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

img{float: left;}

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

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

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

.box #sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float: left;width: 33px;height: 32px;line-height: 32px;padding-left: 26px;}

#sp5{width: 45px}

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

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


</style>


<script type="text/javascript">

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("内容超限");

text.focus();

}else{

alert("提交成功");

}

}

}


</script>

</head>

<body>

<div class="box">

<img src="images/1.jpg">

<div class="box1">还可以输入 <span id="number" >140</span>字</div>

<textarea id="text"></textarea>

<span id="sp1"><i class="fa fa-angle-down"></i>表情</span>

<span id="sp2"><i class="fa fa-angle-down"></i>图片</span>

<span id="sp3"><i class="fa fa-angle-down"></i>视频</span>

<span id="sp4"><i class="fa fa-angle-down"></i>话题</span>

<span id="sp5"><i class="fa fa-angle-down"></i>长微博</span>

<span id="sp6"><i class="fa fa-angle-down"></i>公开</span>

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

</div>

</body>

</html>

 

视频中最后说要在JS里调用aa()不理解,已经有事件触发了。我没有调用,效果也出来了,请教老师解答一下。

批改老师:灭绝师太批改时间:2018-11-15 17:19:34
老师总结:上次在群已经说过了,aa()不需要调用,我内部写了匿名函数,已经自调用了,算是一个小bug,直接去掉函数名就可以了,不需要函数名

发布手记

热门词条