第十章 作业

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

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: 600px;
				margin-left: 200px;
			}
		</style>
	</head>
	<body>
		<p id="img">
			<img src="img/p3.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>

结果

相关推荐
molunnnn5 分钟前
第四章 Agent的几种经典范式
开发语言·python
洛_尘42 分钟前
JAVA EE初阶 2: 多线程-初阶
java·开发语言
@卞2 小时前
C语言常见概念
c语言·开发语言
一只小阿乐2 小时前
react 封装弹框组件 传递数据
前端·javascript·react.js
wjs20242 小时前
Eclipse 关闭项目详解
开发语言
沐知全栈开发2 小时前
《隐藏(Hide)》
开发语言
lkbhua莱克瓦242 小时前
Java基础——方法
java·开发语言·笔记·github·学习方法
533_2 小时前
[element-plus] el-tree 动态增加节点,删除节点
前端·javascript·vue.js
catchadmin2 小时前
PHP 依赖管理器 Composer 2.9 发布
开发语言·php·composer
禁止摆烂_才浅2 小时前
前端开发小技巧-【JavaScript】- 获取元素距离 document 顶部的距离
前端·javascript·react.js