1数字时钟
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代码
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;
}
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
<!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>