第十章 习题

习题一

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>数字时钟</title>
		<style type="text/css">
			div{
				font-size: 150px;
				text-align: center;
			}
			.div{
				font-size: 90px;
				text-align: center;
			}
		</style>
	</head>
	<body>
		<div class="div">数字时钟</div>
		<div id="clock"></div>
		<script>
		        setInterval(function () {
		            var now = new Date();
					//得到时
		            var hours = now.getHours();
					//得到分
		            var minutes = now.getMinutes();
					//得到秒
		            var seconds = now.getSeconds();
					//三元运算符 :条件? 值1 : 值2
		            hours = hours < 10? "0"+hours:hours;
		            minutes = minutes < 10? "0"+minutes:minutes;
		            seconds = seconds < 10? "0"+seconds:seconds;
					//不断更新时间
		            document.getElementById("clock").innerHTML = hours + ":" + minutes + ":" + seconds;
		        }, 1000);
		    </script>
	</body>
</html>

习题二 

PE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>禁止使用鼠标右键</title>
		<style type="text/css">
			img{
				width: 600px;
				height: 400px;
				margin-left: 300px;
			}
		</style>
	</head>
	<body>
			<img src="../js/cat.jpg" id="img"/>
			
		<script type="text/javascript">
			va img=document.getElementById("img");
			//右键对图片的监听事件,onLoad:页面加载完时触发右键监听事件
			window.onload=function(){
			img.addEventListener("contextmenu",function(e){
				e.preventDefault();
				alert("禁止下载图片!");
			});
			}
		</script>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值