news 2026/4/18 9:48:05

WEB 作业 即时内容发布前端交互案例

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
WEB 作业 即时内容发布前端交互案例

在这里我做的是喜灰为主题的

代码如下

<htmllang="zh-CN"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>灰太郎大王新品发布会</title><style>*{margin:0;padding:0;box-sizing:border-box;}body{background-color:#ffffff00;font-family:"Microsoft Yahei",sans-serif;}ul{list-style:none;}.w{width:900px;margin:20px auto;padding:0 10px;}/* 顶部标题 */.top-title{font-size:18px;color:#4171ff;margin-bottom:15px;line-height:1.2;}/* 输入框区域 */.controls{width:100%;}.controls textarea{width:100%;height:120px;resize:none;border:1px solid #5496ff;border-radius:6px;outline:none;padding:10px 15px;font-size:14px;color:#333;margin-bottom:10px;line-height:1.5;}.controls textarea::placeholder{color:#909399;}/* 字数和发布按钮 */.count-btn-box{float:right;display:flex;align-items:center;gap:8px;}.count-btn-box span{font-size:14px;color:#7ba2ef;}.count-btn-box .useCount{color:#6573f6;font-weight:500;}.count-btn-box button{width:88px;height:32px;border:none;outline:none;background-color:#0084ff;color:#fff;font-size:14px;border-radius:4px;cursor:pointer;transition:background-color 0.2s;}.count-btn-box button:hover{background-color:#0078e7;}.count-btn-box button:disabled{background-color:#a0cfff;cursor:not-allowed;}/* 内容列表 */.contentList{margin-top:40px;width:100%;}.contentList li{padding:20px 0;border-bottom:1px dashed #e6e6e6;position:relative;}.contentList li .info{position:relative;min-height:60px;}.contentList li .info img{width:50px;height:50px;border-radius:50%;object-fit:cover;}.contentList li .info .username{position:absolute;top:5px;left:65px;font-size:15px;font-weight:500;color:#333;}.contentList li .info .send-time{position:absolute;top:30px;left:65px;font-size:12px;color:#999;}.contentList li .content{margin-left:65px;margin-top:10px;font-size:14px;color:#666;line-height:1.6;word-break:break-all;}.contentList li .the_del{position:absolute;right:0;top:20px;font-size:18px;color:#999;cursor:pointer;width:20px;height:20px;line-height:20px;text-align:center;}.contentList li .the_del:hover{color:#f56c6c;}/* 清除浮动 */.clearfix::after{content:"";display:block;clear:both;}</style></head><body><divclass="w"><!-- 顶部标题 --><divclass="top-title">灰太郎大王新品发布会</div><!-- 操作的界面 --><divclass="controls clearfix"><textareaplaceholder="请讲"id="area"maxlength="200"></textarea><divclass="count-btn-box"><spanclass="useCount"id="useCount">0</span><span>/</span><span>200</span><buttonid="send"disabled>发布</button></div></div><divclass="contentList"><ulid="list"></ul></div></div><script>letdataArr=[{uname:'暖羊羊',imgSrc:'./111/1.jpg'},{uname:'沸羊羊',imgSrc:'./111/2.jpg'},{uname:'美羊羊',imgSrc:'./111/3.jpg'},{uname:'懒羊羊',imgSrc:'./111/4.jpg'},{uname:'喜羊羊',imgSrc:'./111/5.jpg'},{uname:'慢羊羊',imgSrc:'./111/6.jpg'},{uname:'灰太狼',imgSrc:'./111/7.jpg'},];// 获取DOM元素constarea=document.getElementById('area');constuseCount=document.getElementById('useCount');constsendBtn=document.getElementById('send');constlist=document.getElementById('list');// 1. 实时字数统计 + 发布按钮状态控制area.addEventListener('input',function(){constcurrentLen=this.value.trim().length;useCount.textContent=currentLen;// 按钮可用条件:字数>0 且 ≤200sendBtn.disabled=currentLen===0||currentLen>200;});// 2. 发布功能sendBtn.addEventListener('click',function(){constcontent=area.value.trim();if(!content)return;// 随机选一个用户constrandomIdx=Math.floor(Math.random()*dataArr.length);constrandomUser=dataArr[randomIdx];// 生成当前时间constnow=newDate();constformatTime=(num)=>num.toString().padStart(2,'0');constyear=now.getFullYear();constmonth=formatTime(now.getMonth()+1);constday=formatTime(now.getDate());consthour=formatTime(now.getHours());constminute=formatTime(now.getMinutes());constsecond=formatTime(now.getSeconds());consttimeStr=`${year}${month}${day}${hour}:${minute}:${second}`;// 创建发布项constli=document.createElement('li');li.innerHTML=`<div class="info"> <img src="${randomUser.imgSrc}" alt="${randomUser.uname}" /> <span class="username">${randomUser.uname}</span> <p class="send-time">发布于${timeStr}</p> </div> <div class="content">${content}</div> <span class="the_del">×</span>`;// 插入到列表顶部list.insertBefore(li,list.firstChild);// 绑定删除事件li.querySelector('.the_del').addEventListener('click',function(){li.remove();});// 清空输入框 + 重置字数 + 禁用按钮area.value='';useCount.textContent='0';sendBtn.disabled=true;});</script></body></html>

运行结果:

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/18 8:52:20

基于springboot的就业推荐系统

文章目录详细视频演示项目介绍技术介绍功能介绍核心代码系统效果图源码获取详细视频演示 文章底部名片&#xff0c;获取项目的完整演示视频&#xff0c;免费解答技术疑问 项目介绍 基于SpringBoot的就业推荐系统具有广泛的应用前景和推广价值。它可以应用于高校就业指导中心、…

作者头像 李华
网站建设 2026/4/11 19:20:34

寒假学习(8)(c语言8+模数电8)

对于STM32F103C8T6集成版进行小升级&#xff0c;加入了光敏电阻&#xff0c;热敏电阻&#xff0c;8个小灯&#xff0c;两个按键&#xff0c;macial口改成了type-c&#xff0c;然后改成了自动下载 然后为了省钱又全部改成直插式的了 #include <stdio.h> #include <std…

作者头像 李华
网站建设 2026/4/18 2:09:18

设计客户需求整理工具,录入客户沟通内容,自动提取核心需求,异议点及诉点,生成需求清单,标注优先级,帮销售/运营精准对接客户需求。

1. 实际应用场景与痛点 场景 - 销售/运营在与客户沟通后&#xff0c;需要整理客户需求、异议点和诉求&#xff0c;以便后续跟进。 - 沟通记录通常是语音、聊天记录或笔记&#xff0c;信息杂乱&#xff0c;难以快速提炼重点。 - 手工整理耗时&#xff0c;容易遗漏关键信息。 痛…

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

长尾关键词优化对SEO效果提升的重要性与实践技巧

在数字营销的领域中&#xff0c;长尾关键词优化不仅是提升SEO效果的重要环节&#xff0c;也是吸引精准流量的有效手段。长尾关键词通常由三个到五个词组成&#xff0c;能够明确捕捉用户意图&#xff0c;尤其适合那些有特定需求的用户。通过精确选择并合理布局这些关键词&#x…

作者头像 李华
网站建设 2026/4/18 8:37:27

基于深度学习YOLOv8的道路坑洼识别检测系统(YOLOv8+YOLO数据集+UI界面+Python项目源码+模型)

一、项目介绍 摘要 本项目基于YOLOv8目标检测算法&#xff0c;开发了一套专门用于道路坑洼识别的智能检测系统。该系统能够通过实时图像或视频流自动检测并定位道路表面的坑洼、裂缝等缺陷&#xff0c;为道路维护、交通安全和智慧城市建设提供数据支持。项目采用了一个包含3,…

作者头像 李华
网站建设 2026/4/18 4:31:44

人工智能之数字生命-查找方法的方法的讨论

一、先给结论(直接回答你问的) 1️⃣ 方法节点里的条件节点和结果节点要不要共用一个场景节点? 结论:是“同源但不共用指针”。 逻辑上: 结果场景 = 条件场景 + 方法动作的变化 结构上: 必须是两个独立的场景节点树 但它们来源于同一个“抽象场景模板” 👉 换句话说:…

作者头像 李华