<!DOCTYPE html>
<html>
<head>
     <meta charset='UTF-8'>
	<title>My Website</title>
	<meta name='viewport' content='width=device-width, initial-scale=1.0'>
	<style>
		body {
			margin: 0;
			padding: 0;
		}
		.header {
			background-color: #333;
			color: #fff;
			padding: 10px;
			text-align: center;
		}
		.container {
			padding: 10px;
		}
		.footer {
			background-color: #333;
			color: #fff;
			padding: 10px;
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
		}
		.footer a {
			color: #fff;
			text-decoration: none;
			padding: 10px;
			font-weight: bold;
		}
		.active {
			background-color: #fff;
			color: #333;
		}
        .avatar {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-image: url('./img/avatar.jpg');
            background-size: cover;
        }
        .chat-container {
            display: flex;
            flex-wrap: wrap;
        }
        .chat-card {
            width: 200px;
            margin: 10px;
            background-color: #fff;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
            border-radius: 5px;
            overflow: hidden;
        }
        .chat-card img {
            width: 100%;
            height: 150px;
            object-fit: cover;
        }
        .chat-card .content {
            padding: 10px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        .chat-card .content h3 {
            margin: 0;
            margin-bottom: 5px;
            font-size: 20px;
        }
        .chat-card .content p {
            margin: 0;
            margin-bottom: 5px;
            font-size: 16px;
            color: #666;
        }
	</style>
</head>
<body>
	<div class='header'>
		<h1>My Website</h1>
		<p>./getzuy.json</p>
		<p>时间:<span id='time'></span></p>
		<p>天气:晴</p>
		<div class='avatar'></div>
	</div>
	<div class='container'>
		<h2>欢迎来到我的网站!</h2>
		<p>这里是一个简单的介绍。</p>
		<p><a href='#'>发帖人</a></p>
		<p><a href='#'>发帖简介</a></p>
		<p><a href='#'>原帖链接</a></p>
	</div>
	<div class='chat-container'>
    </div>
	<div class='footer'>
		<a href='#' class='active'>主页</a>
		<a href='#'>推荐</a>
		<a href='#'>启动</a>
		<a href='#'>我的</a>
        <a href='#' onclick='getChatData()'>聊天</a>
	</div>
    <script>
        // 获取系统时间并显示
        function getTime() {
            const date = new Date();
            const hour = date.getHours();
            const minute = date.getMinutes();
            const second = date.getSeconds();
            const timeStr = `${hour < 10 ? '0'+hour : hour}:${minute < 10 ? '0'+minute : minute}:${second < 10 ? '0'+second : second}`;
            document.getElementById('time').innerHTML = timeStr;
        }
        setInterval(getTime, 1000);
<pre><code>    // 获取聊天数据
    function getChatData() {
        const xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 &amp;&amp; this.status == 200) {
                const data = JSON.parse(this.responseText);
                const friends = data.Friends;
                const chatContainer = document.querySelector('.chat-container');
                chatContainer.innerHTML = '';
                friends.forEach(function(friend) {
                    const chatCard = document.createElement('div');
                    chatCard.className = 'chat-card';
                    chatCard.innerHTML = `&lt;img src='${friend.url}' alt='${friend.name}'&gt;&lt;div class='content'&gt;&lt;h3&gt;${friend.name}&lt;/h3&gt;&lt;p&gt;${friend.sex} | ${friend.email}&lt;/p&gt;&lt;p&gt;Last Login: ${friend.lastlogin}&lt;/p&gt;&lt;/div&gt;`;
                    chatContainer.appendChild(chatCard);
                });
            }
        };
        xmlhttp.open('GET', './getzuy.json', true);
        xmlhttp.send();
    }
&lt;/script&gt;
</code></pre>
</body>
</html>
我的网站 - 聊天、推荐、启动

原文地址: https://www.cveoy.top/t/topic/oQzD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录