第十章 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>
相关推荐
Jane-66677711 小时前
C语言——表达式、语句、函数
c语言·开发语言·算法
arron889911 小时前
C# 项目源码进行全面的技术架构和调用逻辑分析。以下是系统性的技术方案
开发语言·架构·c#
88号技师11 小时前
【2025年1区SCI】最新信号分解方法-JMD的参数优化:15种适应度函数-matlab代码
开发语言·matlab·故障诊断·信号分解
zmzb010311 小时前
C++课后习题训练记录Day44
开发语言·c++
smile_Iris11 小时前
Day 30 函数定义与参数
开发语言·python
JokerLee...11 小时前
【Vtable自定义样式】
前端·javascript·vtable
老华带你飞11 小时前
医院挂号|基于Java医院挂号管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot
豐儀麟阁贵11 小时前
9.6使用正则表达式
java·开发语言·数据库·mysql
kgduu11 小时前
go ethreum之Trie
开发语言·后端·golang
Aurorar0rua11 小时前
C Primer Plus 14.17 复习题
c语言·开发语言·数据结构