第十章 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>
相关推荐
柠檬叶子C3 分钟前
【Python】解决 No module named ‘imp‘ 问题 | Python3 中废弃的 imp 模块
开发语言·python
源代码•宸4 分钟前
Golang基础语法(go语言结构体、go语言数组与切片、go语言条件句、go语言循环)
开发语言·经验分享·后端·算法·golang·go
我想吃烤肉肉4 分钟前
wait_until=“domcontentloaded“ 解释
开发语言·前端·javascript·爬虫·python
xkxnq5 分钟前
第一阶段:Vue 基础入门(第 12天)
前端·javascript·vue.js
q_19132846959 分钟前
基于Springboo和vue开发的企业批量排班系统人脸识别考勤打卡系统
前端·javascript·vue.js·spring boot·mysql·毕业设计·人脸识别
BianHuanShiZhe12 分钟前
swift计算文本高度
前端·javascript·html
木木木一14 分钟前
Rust学习记录--C8 常用的集合
开发语言·学习·rust
wtsolutions14 分钟前
Sheet-to-Doc模板设计最佳实践:创建专业的Word模板
前端·javascript·数据库
C_心欲无痕14 分钟前
js - AbortController请求中止
开发语言·javascript·ecmascript