news 2026/7/2 6:54:43

微博发布.html

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
微博发布.html

最终效果展示图:

主要代码:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>微博发布</title> <style> * { margin: 0; padding: 0; } ul { list-style: none; } .w { width: 900px; margin: 0 auto; } .controls textarea { width: 878px; height: 100px; resize: none; border-radius: 10px; outline: none; padding-left: 20px; padding-top: 10px; font-size: 18px; } .controls { overflow: hidden; } .controls div { float: right; display: flex; justify-content: space-between; align-items: center; margin-top: 15px; } .controls div span { color: #666; } .controls div .useCount { color: red; } .controls div button { width: 100px; outline: none; border: none; background: rgb(0, 132, 255); height: 30px; cursor: pointer; color: #fff; font: bold 14px '宋体'; transition: all 0.5s; } .controls div button:hover { background: rgb(0, 225, 255); } .controls div button:active { transform: translateY(1px); } .controls div button:disabled { background: rgba(0, 225, 255, 0.5); } .contentList { margin-top: 50px; } .contentList li { padding: 20px 0; border-bottom: 1px dashed #ccc; position: relative; } .contentList li .info { position: relative; } .contentList li .info span { position: absolute; top: 15px; left: 100px; font: bold 16px '宋体'; } .contentList li .info p { position: absolute; top: 40px; left: 100px; color: #aaa; font-size: 12px; } .contentList img { width: 80px; border-radius: 50%; } .contentList li .content { padding-left: 100px; color: #666; word-break: break-all; } .contentList li .the_del { position: absolute; right: 0; top: 0; font-size: 28px; cursor: pointer; } </style> </head> <body> <div class="w"> <!-- 操作的界面 --> <div class="controls"> <img src="./images/9.6/tip.png" alt="" /><br /> <!-- maxlength 可以用来限制表单输入的内容长度 --> <textarea placeholder="说点什么吧..." id="area" cols="30" rows="10" maxlength="200"></textarea> <div> <span class="useCount" id="useCount">0</span> <span>/</span> <span>200</span> <button id="send">发布</button> </div> </div> <!-- 微博内容列表 --> <div class="contentList"> <ul id="list"></ul> </div> </div> <!-- 添加了hidden属性元素会直接隐藏掉 --> <li hidden id="template"> <div class="info"> <img class="userpic" src="./images/9.6/03.jpg" /> <span class="username">百里守约</span> <p class="send-time">发布于 2026年1月28日 21:41:20</p> </div> <div class="content">111</div> <span class="the_del">X</span> </li> <script> // maxlength 是一个表单属性, 作用是给表单设置一个最大长度 const textarea = document.getElementById('area'); const useCount = document.getElementById('useCount'); const sendBtn = document.getElementById('send'); const list = document.getElementById('list'); const template = document.getElementById('template'); // 模拟数据 let dataArr = [ { uname: '司马懿', imgSrc: './images/9.5/01.jpg' }, { uname: '女娲', imgSrc: './images/9.5/02.jpg' }, { uname: '百里守约', imgSrc: './images/9.5/03.jpg' }, { uname: '亚瑟', imgSrc: './images/9.5/04.jpg' }, { uname: '虞姬', imgSrc: './images/9.5/05.jpg' }, { uname: '张良', imgSrc: './images/9.5/06.jpg' }, { uname: '安其拉', imgSrc: './images/9.5/07.jpg' }, { uname: '李白', imgSrc: './images/9.5/08.jpg' }, { uname: '阿珂', imgSrc: './images/9.5/09.jpg' }, { uname: '墨子', imgSrc: './images/9.5/10.jpg' }, { uname: '鲁班', imgSrc: './images/9.5/11.jpg' }, { uname: '嬴政', imgSrc: './images/9.5/12.jpg' }, { uname: '孙膑', imgSrc: './images/9.5/13.jpg' }, { uname: '周瑜', imgSrc: './images/9.5/14.jpg' }, { uname: '老夫子', imgSrc: './images/9.5/15.jpg' }, { uname: '狄仁杰', imgSrc: './images/9.5/16.jpg' }, { uname: '扁鹊', imgSrc: './images/9.5/17.jpg' }, { uname: '马可波罗', imgSrc: './images/9.5/18.jpg' }, { uname: '露娜', imgSrc: './images/9.5/19.jpg' }, { uname: '孙悟空', imgSrc: './images/9.5/20.jpg' }, { uname: '黄忠', imgSrc: './images/9.5/21.jpg' }, { uname: '百里玄策', imgSrc: './images/9.5/22.jpg' }, ]; // 初始化:添加一些示例微博 function initExamples() { const examplePosts = [ { content: '今天非常的开心!', userIndex: 0 }, ]; examplePosts.forEach(post => { addWeibo(post.content, dataArr[post.userIndex]); }); } // 实时更新字数统计 textarea.addEventListener('input', function () { const count = this.value.length; useCount.textContent = count; // 如果字数超过200,截断 if (count > 200) { this.value = this.value.substring(0, 200); useCount.textContent = 200; } // 启用/禁用发布按钮 sendBtn.disabled = this.value.trim().length === 0; }); // 获取当前时间格式化字符串 function getCurrentTime() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); const hour = String(now.getHours()).padStart(2, '0'); const minute = String(now.getMinutes()).padStart(2, '0'); const second = String(now.getSeconds()).padStart(2, '0'); return `${year}年${month}月${day}日 ${hour}:${minute}:${second}`; } // 添加微博到列表 function addWeibo(content, user) { // 克隆模板 const newWeibo = template.cloneNode(true); newWeibo.removeAttribute('hidden'); newWeibo.removeAttribute('id'); // 设置内容 newWeibo.querySelector('.userpic').src = user.imgSrc; newWeibo.querySelector('.username').textContent = user.uname; newWeibo.querySelector('.send-time').textContent = `发布于 ${getCurrentTime()}`; newWeibo.querySelector('.content').textContent = content; // 添加到列表最前面 list.insertBefore(newWeibo, list.firstChild); // 为删除按钮添加事件 const delBtn = newWeibo.querySelector('.the_del'); delBtn.addEventListener('click', function () { if (confirm('确定要删除这条微博吗?')) { list.removeChild(newWeibo); } }); } // 发布按钮点击事件 sendBtn.addEventListener('click', function () { const content = textarea.value.trim(); if (content.length === 0) { alert('请输入微博内容!'); return; } // 随机选择一个用户 const randomUser = dataArr[Math.floor(Math.random() * dataArr.length)]; // 添加微博 addWeibo(content, randomUser); // 清空输入框 textarea.value = ''; useCount.textContent = '0'; sendBtn.disabled = true; // 滚动到顶部 window.scrollTo({ top: 0, behavior: 'smooth' }); }); // 按Enter键发布,按Ctrl+Enter换行 textarea.addEventListener('keydown', function (e) { if (e.key === 'Enter' && !e.ctrlKey) { e.preventDefault(); sendBtn.click(); } }); // 页面加载完成时初始化示例微博 document.addEventListener('DOMContentLoaded', function () { initExamples(); }); </script> </body> </html>
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/1 13:38:44

WuliArt Qwen-Image Turbo实际项目:独立开发者构建本地化AI作图SaaS原型

WuliArt Qwen-Image Turbo实际项目&#xff1a;独立开发者构建本地化AI作图SaaS原型 1. 为什么一个独立开发者需要自己的AI作图引擎&#xff1f; 你有没有过这样的经历&#xff1a;想快速把脑子里的画面变成一张图&#xff0c;却卡在了注册、登录、充值、额度用完、等待排队、…

作者头像 李华
网站建设 2026/6/30 20:59:34

Qwen3-VL-8B企业应用部署:Nginx反向代理+基础认证安全加固方案

Qwen3-VL-8B企业应用部署&#xff1a;Nginx反向代理基础认证安全加固方案 在企业环境中直接暴露AI服务接口存在明显风险——未授权访问、恶意调用、敏感对话泄露、API滥用等问题频发。很多团队完成Qwen3-VL-8B本地部署后&#xff0c;发现http://localhost:8000/chat.html能跑通…

作者头像 李华
网站建设 2026/6/26 21:47:24

VibeVoice Pro开源可部署方案:无需云服务,本地GPU私有化语音基座

VibeVoice Pro开源可部署方案&#xff1a;无需云服务&#xff0c;本地GPU私有化语音基座 1. 为什么你需要一个“能马上开口”的语音引擎 你有没有遇到过这样的场景&#xff1a; 在做实时AI客服时&#xff0c;用户刚打完字&#xff0c;系统却要等2秒才开始说话&#xff1b;开…

作者头像 李华
网站建设 2026/6/13 13:19:21

web前端练习题

练习一&#xff1a;综合成绩统计与评级系统 编写一个名为 analyzeGrades 的函数&#xff0c;该函数接收一个包含若干学生成绩&#xff08;0-100之间的数字&#xff09;的数组作为参数。请完成以下功能&#xff1a; 数据清洗&#xff1a;过滤掉数组中无效的数据&#xff08;非…

作者头像 李华
网站建设 2026/7/1 20:40:41

亲测麦橘超然Flux镜像,中低显存也能玩转AI绘画

亲测麦橘超然Flux镜像&#xff0c;中低显存也能玩转AI绘画 1. 为什么这款Flux镜像值得你立刻试试&#xff1f; 你是不是也经历过这些时刻&#xff1a; 看到别人用AI生成惊艳画作&#xff0c;自己却卡在“显存不足”报错上&#xff1b;下载完几个GB的模型&#xff0c;启动就崩…

作者头像 李华
网站建设 2026/6/13 13:44:21

Qwen3-Embedding-4B部署教程:阿里云ECS+GPU实例一键部署语义搜索服务

Qwen3-Embedding-4B部署教程&#xff1a;阿里云ECSGPU实例一键部署语义搜索服务 1. 为什么你需要一个真正的语义搜索服务&#xff1f; 你有没有遇到过这样的问题&#xff1a;在自己的文档、产品说明或客服知识库中&#xff0c;用户输入“手机充不进电”&#xff0c;而你的检索…

作者头像 李华