当前位置: 首页 > news >正文

“打造个性化留言板:从页面搭建到功能实现“

White graces:个人主页

🙉专栏推荐:Java入门知识🙉

🐹今日诗词:红叶晚萧萧,长亭酒一瓢🐹


⛳️点赞 ☀️收藏⭐️关注💬卑微小博主🙏

⛳️点赞 ☀️收藏⭐️关注💬卑微小博主🙏


目录

预期效果

1. 页面搭建

2. 将内容显示到页面

3. 所有代码

美图分享


预期效果

1. 页面搭建

页面搭建很简单, 代码如下

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>留言板</title><style>.container {width: 350px;height: 300px;margin: 0 auto;/* border: 1px black solid; */text-align: center;}.grey {color: grey;}.container .row {width: 350px;height: 40px;display: flex;justify-content: space-between;align-items: center;}.container .row input {width: 260px;height: 30px;}#submit {width: 350px;height: 40px;background-color: orange;color: white;border: none;margin: 10px;border-radius: 5px;font-size: 20px;}</style>
</head><body><div class="container"><h1>留言板</h1><p class="grey">输入后点击提交, 会将信息显示下方空白处</p><div class="row"><span>谁:</span> <input type="text" name="" id="from"></div><div class="row"><span>对谁:</span> <input type="text" name="" id="to"></div><div class="row"><span>说什么:</span> <input type="text" name="" id="say"></div><input type="button" value="提交" id="submit" onclick="submit()"></div><script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script><script>function submit(){}</script>
</body></html>

2. 将内容显示到页面

首先要获取到用户输入的信息

 function submit(){let from = $("#from").val();let to = $("#to").val();let say = $("#say").val();let message = "<div>" + from + "对" + to + "说" + say + "</div>";$(".container").append(message);$("#from").val("");$("#to").val("");$("#say").val("");}

3. 所有代码

温馨提示: 如果复制所有代码到自己的电脑上运行失败

原因只有一个: 就是引入的JQuery库有问题, 这个跟你当前网络环境有关, 可以尝试将JQuery库下载到本地再引入

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>留言板</title><style>.container {width: 350px;height: 300px;margin: 0 auto;/* border: 1px black solid; */text-align: center;}.grey {color: grey;}.container .row {width: 350px;height: 40px;display: flex;justify-content: space-between;align-items: center;}.container .row input {width: 260px;height: 30px;}#submit {width: 350px;height: 40px;background-color: orange;color: white;border: none;margin: 10px;border-radius: 5px;font-size: 20px;}</style>
</head><body><div class="container"><h1>留言板</h1><p class="grey">输入后点击提交, 会将信息显示下方空白处</p><div class="row"><span>谁:</span> <input type="text" name="" id="from"></div><div class="row"><span>对谁:</span> <input type="text" name="" id="to"></div><div class="row"><span>说什么:</span> <input type="text" name="" id="say"></div><input type="button" value="提交" id="submit" onclick="submit()"></div><script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js"></script><script>function submit(){let from = $("#from").val();let to = $("#to").val();let say = $("#say").val();if(from == "" || to == "" || say == "") {return;}let message = "<div>" + from + "对" + to + "说" + say + "</div>";$(".container").append(message);$("#from").val("");$("#to").val("");$("#say").val("");}</script>
</body></html>

美图分享

✨🎆谢谢你的阅读和耐心!祝愿你在编程的道路上取得更多的成功与喜悦!"🎆✨🎄

⭐️点赞收藏加关注,学习知识不迷路⭐️

🎉✔️💪🎉✔️💪🎉✔️💪🎉✔️💪🎉

👍😏⛳️点赞☀️收藏⭐️关注😏👍

👍😏⛳️点赞☀️收藏⭐️关注😏👍

👍😏⛳️点赞☀️收藏⭐️关注😏👍

🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️🙆‍♂️


http://www.mrgr.cn/news/53922.html

相关文章:

  • 分布式ID生成策略
  • 视频网站开发:Spring Boot框架的深入探索
  • 23种设计模式具体实现方法
  • android 与网页交互通过网页修改宿主布局和异常处理——未来之窗行业应用跨平台架构
  • 【【自动驾驶】车辆运动学模型】
  • 软件设计模式------概述
  • 代码随想录day4| 24. 两两交换链表中的节点 、19.删除链表的倒数第N个节点 、面试题 02.07. 链表相交、 142.环形链表II、链表总结
  • OpenGL 自定义SurfaceView Texture C++预览Camera视频
  • 浮动练习(1)
  • Vue3学习:vite项目中图片不能显示,报错 require is not defined
  • 《计算机视觉》—— 表情识别
  • UML图画法(动态图):用例图(Use Case Diagram)
  • 高级语言源程序转换为可执行目标文件
  • Leetcode - 周赛419
  • HTB:Bashed[WriteUP]
  • 下载nltk数据
  • 详细尝鲜flutter
  • 递归神经网络(RNN)简介
  • MySQL查看当前客户端连接数的方法
  • NOIP2007年复赛
  • 【北京迅为】《STM32MP157开发板嵌入式开发指南》- 第五十四章 Pinctrl 子系统和 GPIO 子系统
  • D-PAD论文解析
  • 虚拟机nacos部署报错数据源未设置问题解决方案
  • 逻辑之舞:C++ 内存分配与释放,在程序的舞台上,演绎着资源的分配与回收
  • 解决SolidWorks装配体无法更改透明度问题
  • 【数据结构】栈