第十章 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>
相关推荐
weixin_4723394614 分钟前
高效处理大体积Excel文件的Java技术方案解析
java·开发语言·excel
枯萎穿心攻击1 小时前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
Eiceblue2 小时前
【免费.NET方案】CSV到PDF与DataTable的快速转换
开发语言·pdf·c#·.net
m0_555762903 小时前
Matlab 频谱分析 (Spectral Analysis)
开发语言·matlab
像风一样自由20203 小时前
HTML与JavaScript:构建动态交互式Web页面的基石
前端·javascript·html
浪裡遊4 小时前
React Hooks全面解析:从基础到高级的实用指南
开发语言·前端·javascript·react.js·node.js·ecmascript·php
lzb_kkk4 小时前
【C++】C++四种类型转换操作符详解
开发语言·c++·windows·1024程序员节
好开心啊没烦恼5 小时前
Python 数据分析:numpy,说人话,说说数组维度。听故事学知识点怎么这么容易?
开发语言·人工智能·python·数据挖掘·数据分析·numpy
简佐义的博客5 小时前
破解非模式物种GO/KEGG注释难题
开发语言·数据库·后端·oracle·golang
Liudef065 小时前
2048小游戏实现
javascript·css·css3