发现课程代码中一个BUG。当文本框没有获取到焦点的时候,直接点提交。视频里的代码貌似会提示发布成功

原创2018-11-20 00:04:4555
摘要:发现课程代码中一个BUG。当文本框没有获取到焦点的时候,直接点提交。视频里的代码貌似会提示发布成功,因为这个时候M不等于140也不小于0,这时的值是:undefined<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Document</title&g

发现课程代码中一个BUG。当文本框没有获取到焦点的时候,直接点提交。视频里的代码貌似会提示发布成功,因为这个时候M不等于140也不小于0,这时的值是:undefined


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

<style>

#box{width: 800px; height: 300px; border: 8px solid pink; margin: 0px auto;padding: 15px;}

#jishu{font-size: 14px; font-weight: bold; color: #ccc; font-family: 宋体;margin-right: 20px;margin-left: 475px; line-height: 20px;}

#neirong{width: 780px; height: 230px;border:2px solid #ccc; margin-top: 5px;}

.sp1,.sp2,.sp3,.sp4,.sp5,.sp6{line-height: 25px;padding-left: 26px; width: 40px; height: 30px; font-size: 14px;}

.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;}

.sp6{margin-left: 320px;color: #888;}

#fabu{margin-left: 10px;width: 70px;height: 30px;border:0px; background: #FFC79E; border-radius: 5px;}

</style>


<script>

var m,num,text,tijiao;

window.onload=function() {

tijiao=document.getElementById("fabu")

text=document.getElementById("neirong");

num=document.getElementById("num");

m=140-text.value.length

text.onkeyup=function a(){

m=140-text.value.length

if (m<0) {

num.style.color="red"

}else{

num.style.color="#888"

}

num.innerHTML=m

}

tijiao.onclick=function (){

if (m==140) {

alert("您还没有输入内容!")

text.focus()

}else if(m<0){

alert("字数太多,无法发布!")

text.focus()

}else{

alert("发布成功!")

}

}


}


</script>

</head>

<body>



<div id="box">

<img src="images/12.png" alt=""><span id="jishu">还可以输入<b id="num"></b>字</span>

<textarea id="neirong"></textarea>

<span>表情</span>

<span>图片</span>

<span>视频</span>

<span>话题</span>

<span>长微博</span>

<span>公开</span>

<input type="button" value="发布" ID="fabu">

</div>

</body>

</html>


批改老师:灭绝师太批改时间:2018-11-20 09:04:01
老师总结:其实也不是bug,这里少做了一个判断啦,自己加上!

发布手记

热门词条