1数字时钟
HTML代码
html
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@import url(./css/1.css);
</style>
<meta charset="UTF-8">
<title>数字时钟</title>
</head>
<body>
<div class="top">
<p>数字时钟</p>
</div>
<div class="clock" id="clock"><script src="js/1.js"></script>
</div>
</body>
</html>
css代码
html
body{
align-items: center;
height: 100px;
background-color:#ffffff;
color: black;
}
.clock {
font-size: 100px;
border: none;
padding: 20px;
border-radius: 10px;
background-color: rgba(255, 255, 255, 0.1);
text-align: center;
}
.top,p{
font-size: 100px;
text-align: center;
}
html
function updateClock() {
const now = new Date();
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
const timeString = `${hours}:${minutes}:${seconds}`;
document.getElementById('clock').textContent = timeString;
}
// 每秒更新一次时钟
setInterval(updateClock, 1000);
// 初始化时钟
updateClock();
2
html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>禁止下载</title>
<script>
// 禁用右键菜单并弹出警告
function showAlert(e) {
e.preventDefault(); // 阻止默认右键菜单
alert("禁止下载图片!"); // 弹出警告对话框
}
// 添加事件监听器
document.addEventListener('DOMContentLoaded', function() {
const images = document.querySelectorAll('img'); // 选择所有图片
images.forEach(img => {
img.addEventListener('contextmenu', showAlert); // 为每个图片添加右键事件
});
});
</script>
</head>
<body>
<img src="img/p1.jpg" alt="示例图片" style="max-width: 100%; height: auto;">
</body>
</html>