微博输入字数

原创 2018-11-14 22:24:16 312
摘要:<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>微博输入</title> <style type="text/css"> body{font-size: 
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>微博输入</title>
	<style type="text/css">
		body{font-size: 12px;}
		.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;text-align: right;font-size: 14px;;color: #888;}
		#text{width: 600px;height: 100px;border: 1px solid #888;}
		.box #sp1,#sp2,#sp3,#sp4,#sp5,#sp6{float: left;width: 30px;height: 30px;line-height: 30px;padding-left: 26px;}
		#sp1{background: url(images/an5.png) no-repeat left;}
		#sp2{background: url(images/an4.png) no-repeat left;}
		#sp3{background: url(images/an3.png) no-repeat left;}
		#sp4{background: url(images/an2.png) no-repeat left;}
		#sp5{background: url(images/an1.png) no-repeat left;width: 50px;}
		#sp6{margin-left: 140px;margin-right: 15px;color: #888;}
		#bt{float: left;width: 80px;height: 30px;background-color: #ffc09f;border: none;color: #fff;border-radius: 5px;}
	</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(){
				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 || m==null){
					alert("您还没有输入!");
					text.focus();
				}else if(m<0){
					alert("您的字数过多!");
					text.focus();
				}else{
					alert("发布成功!");
					text.focus();					
				}
			}
		}
	</script>
</head>
<body>
<div class="box">
	<img src="images/12.png" id="img1">
	<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="点击" id="bt">
</div>
</body>
</html>

这一节主要学习和复习了对Javascript的应用

window.onload=function()  //指页面加载完成就调用该函数!

document.getElementById()  //通过ID来查找获取对象

text.onkeyup=function(){}   //键盘被松开调用函数

text.value.length   //把目标转换为数字类型,并得出长度

number.style.color  //改变css的颜色

number.innerHTML=m  //修改HTML元素内容,添加元素内容


批改老师:灭绝师太批改时间:2018-11-15 09:03:20
老师总结:完成的和总结的都很不错,知识点分解的比较好,相信有花功夫

发布手记

热门词条