第十章 JavaScript的应用课后习题

1.在网页中显示一个工作中的"数字时钟"。

参考代码:

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>动态时钟</title>
	<style>
		.all{
			width: 600px;
			height: 300px;
			margin: 100px auto;
			text-align: center;
			font-size: 50px;
		}
		#clock{
			margin-top: 50px;
			margin-left: 100px;
			width: 400px;
			height: 100px;
			font-size: 100px;
			text-align: center;
			font: bold;
			color: black;
		}
		.text{
			font-size: 30px;
			font-weight: bold;
		}
	</style>
	<script type="text/javascript">
			function showTime(clock){
				var now = new Date();
				var hour = now.getHours();
				var minu = now.getMinutes();
				var second = now.getSeconds();
				var time =hour+":"+minu+":"+second;
				clock.innerHTML=time;
			}
			window.onload = function(){
				var clock = document.getElementById("clock");
				window.setInterval("showTime(clock)",1000);
			  
			}
			</script>
	</head>
	<body>
		<div class="all">
			<p>数字时钟</p >
			<div id ="clock"></div>
		</div>	
	</body>
</html>

2.制作一个"禁止使用鼠标右键"操作的网页。当浏览者在页面上右击时,自动弹出一个警告对话框,禁止用户使用右键快捷菜单。

参考代码:

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>禁止下载</title>
		<style>
			img{
				width: 600px;
				height: 400px;
				margin-left: 200px;
			}
		</style>
	</head>
	<body>
		<p id="img">
			<img src="img/cat.jpg" />
		</p >
		<script type="text/javascript">
			var demo=document.getElementById("img");
			demo.oncontextmenu=a;
			function a(){
				alert("禁止下载图片!");
			}
			document.addEventListener('contextmenu',function(b){
				b.preventDefault();  //阻止上下文菜单
			});
		</script>
	</body>
</html>
相关推荐
小陈同学呦7 小时前
前端如何处理订单状态导航的数据竞态问题
前端·javascript
开发者每周简报7 小时前
网海三部曲·无名宗师传
javascript·人工智能
isyangli_blog8 小时前
OpenDayLight (Carbon 版本) 启动与组件安装
开发语言·php
vb2008118 小时前
FastAPI APIRouter
开发语言·python
Benszen8 小时前
KVM虚拟化解决方案
开发语言·perl
会编程的土豆8 小时前
Go 语言反射(Reflection)详解
开发语言·后端·golang
東雪木8 小时前
多线程与并发编程 专属复习笔记
java·开发语言·笔记·java面试
杨充8 小时前
1.3 浮点型数据设计灵魂
开发语言·python·算法
噜噜噜阿鲁~8 小时前
python学习笔记 | 11.3、面向对象高级编程-多重继承
java·开发语言
basketball6169 小时前
Go 语言从入门到进阶:4. 数组和MAP使用方法总结
开发语言·后端·golang