前端练习题

1.完成注册表单(参考图片,使用表格布局css修饰即可)

在这里插入图片描述
代码演示

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册表单</title>
		
		<style type="text/css">
				
			form,table{
				width: 500px;
				margin: auto;
			}
			
			.one,.three,.four{
				text-align: center;
			}
			
			.one,.three{
				height: 25px;
				background-color: #1E90FF;
			}
			
			
			.zero{
				width: 500px;
				background-color: skyblue;
			}
			
			.explain{
				width: 150px;
				text-align: right;
			}
			
		</style>
		
	</head>
	<body>
		<form class="zero">
			<table>
				<tr >
					<td colspan="2" class="one"><h2 class="one">欢迎注册</h2></td>
				</tr>
				<div class="two">
					<tr>
						<td class="explain">用户名:</td>
						<td class="content">
							<input type="text" />
						</td>
					</tr>
					<tr>
						<td class="explain">密码:</td>
						<td>
							<input type="password" />
						</td>
					</tr>
					<tr>
						<td class="explain">性别:</td>
						<td>
							<input type="radio" name="gender" value="" checked="checked"/><input type="radio" name="gender" value="" /></td>
					</tr>
					<tr>
						<td class="explain">电话:</td>
						<td>
							<input type="text" />
						</td>
					</tr>
					<tr>
						<td class="explain">职业:</td>
						<td>
							<select >
								<option value="" >请选择</option>
								<option value="程序猿" >程序猿</option>
								<option value="工程狮" >工程狮</option>
							</select>
						</td>
					</tr>
					<tr>
					<td class="explain">爱好:</td>
						<td>
							<input type="checkbox" name="hobby" />敲代码
							<input type="checkbox" name="hobby" />打游戏
							<input type="checkbox" name="hobby" />唱歌
							<input type="checkbox" name="hobby" />运动
						</td>
					</tr>
					<tr>
						<td class="explain">地址:</td>
							<td>
								<textarea cols="30" rows="3"></textarea>
							</td>
					</tr>
				</div>
				<tr>
					<td colspan="2" class="three">填写完成后点击下面提交按钮提交表单</td>
				</tr>
				<tr>
					<td colspan="2" class="four">
						<input type="submit" class="button" />
						<input type="reset"  class="button" />
					</td>
				</tr>
			</table>
		
		</form>

	</body>
</html>


2.有一个按钮,和一个div如图,点击按钮使得div消失,之后将按钮文字改变为显示,再次点击按钮使得div出现,依次类推.

在这里插入图片描述
在这里插入图片描述
代码演示

<!-- 方法一 -->
<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function oper(btnobj){
				
				var divobj=document.getElementById("div1");
				if(btnobj.value=="隐藏"){
			/* 
					 通过display样式可以修改标签的类型。
					 block:设置标签为块标签
					 none :隐藏标签(标签将在页面中完全消失)
					 */
					divobj.style.display="none";
					btnobj.value="显示";
				}else{
					divobj.style.display="block";
					btnobj.value="隐藏";
				}
			}
		</script>
	</head>
	<body>
	
		<!--
		有一个按钮,和一个div如图,点击按钮使得div消失,之后将按钮文字改变为显示,再次点击按钮使得div出现,依次类推. 
		 -->
		 <input type="button" value="隐藏"  onclick="oper(this)" >
		 <div id="div1" style="width: 200px;height: 200px; background-color: blue;">
			 
		 </div>
	</body>
</html>
<!-- 方法二 -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function show(){
				var btnobj=document.getElementById("btn1");
				var divobj=document.getElementById("div1");
				if(btnobj.value=="隐藏"){
					divobj.style.display="none";
					btnobj.value="显示";
				}else{
					divobj.style.display="block";
					this.value="隐藏";
				}
			}
		

		</script>
	</head>
	<body>
	<!-- 
	有一个按钮,和一个div如图,点击按钮使得div消失,之后将按钮文字改变为显示,再次点击按钮使得div出现,依次类推. 
	 -->
	<input type="button" value="隐藏" onclick="show()" id="btn1">
	<div id="div1" style="width: 200px; height: 200px; background-color: aqua;">
		
	</div>
	</body>
</html>

3.完成下图(界面仅供参考)

选择下拉框,对文本域进行字体,颜色,大小设置
在这里插入图片描述
代码演示

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			*{
				padding: 0px;
				border: 0px;
			}
			.box{
				width: 400px;
				margin: 0 auto;
			}
			.title{
				width: 350px;
				text-align: center;
				color: #5F9EA0;
			
			}
			.head{
				width: 350px;
				background-color: #DFE9F5;
			}
			.head_left,
			.head_mid,
			.head_right{
				float: left;
				margin: 0 8px;
				 
			}
		     .head_left_left,
			 .head_left_mid,
			 .head_left_right{
				 border: 1px black solid;
				 width: 100px;
				 position: relative;
				 border-radius:5px 5px 0px 0px;
				
			 }
		    
			.bottom_textarea{
				border: 1px skyblue solid;
				background-color: #FFFFCC;
			}
		</style>
		<script type="text/javascript">
			function changecolor(colorOptions){
				var textObj=document.getElementById("text");
				textObj.style.color=colorOptions.options[colorOptions.selectedIndex].value;
			}
			function changesize(sizeOptions){
				var textObj=document.getElementById("text");
				textObj.style.fontSize=sizeOptions.options[sizeOptions.selectedIndex].value;
			}
			function changefamily(familyOptions){
				var textObj=document.getElementById("text");
				textObj.style.fontFamily=familyOptions.options[familyOptions.selectedIndex].value;
			}
		</script>
	</head>
	<body>
		<!-- 
		 选择下拉框,对文本域进行字体,颜色,大小设置
		 -->
		 <div class="box">
			 <div class="title">
				 <h1>文本编辑器</h1>
			 </div>
		 <div class="head">
			 <div class="head_left">
				 <!-- 
				 onchange()是指当前标签失去焦点并且标签的内容发生改变时触发事件处理程序
				 -->
				 <select class="head_left_left"  onchange="changecolor(this)">
					 <option>字体颜色</option>
					 <!-- color:字体颜色 -->
					 <option value="red" id="ired">红色</option>
					 <option value="blue" id="iblue">蓝色</option>
				 </select>
			 </div>
			 <div class="head_mid">
				 <select class="head_left_mid"  onchange="changesize(this)">
					 <!-- font-size:字体大小-->
					 <option>字体大小</option>
					 <option value="20px" id="i20">20px</option>
					 <option value="40px" id="i40">40px</option>
				 </select>
			 </div>
			 <div class="head_right">
				 <select class="head_left_right" onchange="changefamily(this)">
					 <!-- font-family:字体-->
					 <option>字体</option>
					 <option value="楷体" id="i楷体">楷体</option>
					 <option value="serif" id="iserif">serif</option>	
				 </select>
			 </div>
			 <div style="clear: left;"></div>
		 </div>
		 <div class="bottom">
	    <textarea class="bottom_textarea" cols="50" rows="15" id="text"></textarea>
	    </div>
	</div>
	</body>
</html>

4.完成简单的计算器

在这里插入图片描述

代码演示

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			*{
				padding: 0px;
				border: 0px;
			}
			.box{
				width: 370px;
				height: 250px;
				background-color: lightgray;
				border-right: 0px;
				position: absolute;
				left: 35%;
			}
			.ONE,
			.TWO,
			.three,
			.four{
				float:left;
				position: relative;
				left: 35px;
				width: 300px;
				text-align: center;
				border-right: 0px;
			}
			#text{
			    
				width: 290px;
				height: 40px;
				background-color: azure;
				font-size: 30px;
				margin: 2px auto;
				border: 2px black solid;
				
				
			}
			.ONE input,
			.TWO input,
			.three input,
			.four input{
				width: 70px;
				height: 40px;
				margin: 5px auto;
				border-right: 3px grey solid;
			}
			
		</style>
		<script type="text/javascript">
			function clickNum(num){
				//数字
			var textobj=document.getElementById("text");
			textobj.innerHTML=textobj.innerHTML+num;
			}
			function clickop(op){
				var textobj=document.getElementById("text");
				textobj.innerHTML+=op;
			}
			function equa(){
				/* eval(arg) 可运算某个字符串。 */
				var textobj=document.getElementById("text");
				var expression=textobj.innerHTML;
				textobj.innerHTML=eval(expression);
			}
			function back(){
				/* 清空 */
				document.getElementById("text").innerHTML="";
			}
		</script>
	</head>
	<body class="on1">
		<div class="box">
			<div id="text">
				
			</div>
			 
			<div class="ONE">
				<input type="button" value="7" onclick="clickNum(7)">
				<input type="button" value="8"  onclick="clickNum(8)">
				<input type="button" value="9" onclick="clickNum(9)">
				<input type="button" value="+" onclick="clickop('+')">
			</div>
			<div class="TWO">
				<input type="button" value="4" onclick="clickNum(4)">
				<input type="button" value="5" onclick="clickNum(5)">
				<input type="button" value="6" onclick="clickNum(6)">
				<input type="button" value="-" onclick="clickop('-')">
			</div>
			<div class="three">
			<input type="button" value="1" onclick="clickNum(1)">
			<input type="button" value="2" onclick="clickNum(2)">
			<input type="button" value="3" onclick="clickNum(3)">
			<input type="button" value="*" onclick="clickop('*')">
			</div>
			<div class="four">
				<input type="button" value="0" onclick="cliknum(0)">
				<input type="button" value="c" onclick="back()">
				<input type="button" value="=" onclick="equa()">
				<input type="button" value="/" onclick="clickop('/')">
			</div>
		</div>
	</body>
</html>

5.制作一个计数器 如图,点击开始从1开始计数,点击停止,停止计数,点击复位归0并结束计数。

在这里插入图片描述
代码如下

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>计时器</title>
		<style type="text/css">
			*{
				padding: 0px;
				margin: 0px;
			}
			.box{
				width: 300px;
				height: 300px;
				margin: 100px auto;
				border-radius:50%;
				background-color: antiquewhite;
				border: 5px black solid;
			}
			#screen{
				background-color: aqua;
				font-size: 20px;
				color: blue;
				width: 70px;
				height: 30px;
				position: relative;
				top: 30px;
				left: 80px;
				padding: 5px 10px 5px 60px;
			}
			#start_id,#stop_id,#reset_id{
				width: 50px;
				height: 40px;
				float: left;
				position: relative;
				top:50px;
				left: 10px;
				border-radius: 50%;
				margin: 20px 20px;
			}
		</style>
		<script type="text/javascript">	
			var t;
			function add(){
				var screenObj=document.getElementById("screen");
				var Number=parseInt(screenObj.value)+1;
				screenObj.value=""+Number;
			}
			function start(){
				/*
				 setInterval是一个实现定时调用的函数,可按照指定的周期(以毫秒计)来调用函数或计算表达式。
				 setInterval方法会不停地调用函数,直到 clearInterval被调用或窗口被关闭。
				 */
				t=setInterval("add()",100);
			}
			function stop(){
				clearInterval(t);
				/* console.log方法用于在控制台输出信息。它可以接受一个或多个参数,将它们连接起来输出。 */
				console.log("停止了一次");
			}
			function reset(){
				document.getElementById("screen").value="1";
			}	
		</script>
	</head>
	<body>
			<div class="box">
			    <input type="text" value="1" readonly="readonly" id="screen" /><br>
				<input type="button" value="开始" id="start_id" onclick="start()">
				<input type="button" value="停止" id="stop_id"  onclick="stop()">
				<input type="button" value="复位" id="reset_id" onclick="reset()">
			</div>	
	</body>
</html>

6.在网页中显示一个电子表,格式为年月日 时分秒的时间,使其每秒更新一次.

在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			*{
				padding: 0px;
				margin: 0px;
			}
			.box{
				width: 400px;
				height: 100px;
				background-color: black;
				margin:auto;
				margin-top: 100px;
				
			}
			.clock{
				text-align: center;
				color: white;
				font-size: 30px;
				padding-top: 20px;
				
			}
		</style>
		<script type="text/javascript">
			var t=setInterval("test()",100);
			function test(){
				var date=new Date();
				var timeObj=document.getElementsByClassName("time_id");
				timeObj[0].innerHTML=date.getFullYear()+"年";
				timeObj[1].innerHTML=date.getMonth()+1+"月";
				timeObj[2].innerHTML=date.getDate()+"日";
				timeObj[3].innerHTML=date.getHours()+":";
				timeObj[4].innerHTML=date.getMinutes()+":";
				timeObj[5].innerHTML=date.getSeconds();
				
			}
		</script>
	</head>
	<body>
		<div class="box">
			<div class="clock">
			<!-- 	getElementById 是通过id来获取元素,id在HTML中是唯一的,所以获取到的只有一个元素。
				
				getElementsByTagNam 是通过标签名来获取元素,一种标签在HTML中可以有多个,所以获取到的是多个元素,且返回是以集合的形式返回。
				
				getElementsByClassName 是通过类名来获取元素,同名的类在HTML中也能存在多个,所以获取到的也是多个元素,同样是以集合的形式反回。 -->
			
				<span class="time_id"></span>
				<span class="time_id"></span>
				<span class="time_id"></span>
				<span class="time_id"></span>
				<span class="time_id"></span>
				<span class="time_id"></span>
			</div>
		</div>
	</body>
</html>
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值