案例-表白墙简单实现

文章目录

效果展示

初始画面

提交内容后画面(按键按下)

代码区

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
</head>
<style>
    * {
        margin: 0px;
        padding: 0px;
    }
    .total {
        width: 400px;
        margin: 0px auto; /*上下、左右*/
    }
    h1 {
        text-align: center;
        padding-bottom: 30px;
    }
    p {
        text-align: center;
        color: gray;
    }
    .div1 {
        display: flex;
        justify-content: center; /*水平方向*/
        align-items: center; /*垂直方向*/
        padding-top: 5px;
    }
    span {
        width: 80px;
        height: 30px;
    }
    #edit {
        width: 200px;
        height: 30px;
    }
    .submit {
        width: 280px;
        height: 30px;
        background-color: rgba(248, 236, 7, 0.942);
        border: none;
        border-radius: 5px;
    }
    .submit:active{
        background-color: grey;
    }
</style>
<body>
    <div class="total">
        <h1>表白墙</h1>
        <p>输入后请点击提交,会将信息显示在表格中</p>
        <div class="div1">
            <span>谁:</span><input id="edit" class="who" type="text">
        </div>
        <div class="div1">
            <span>对谁:</span><input id="edit" class="ofwho" type="text">
        </div>
        <div class="div1">
            <span>说什么</span><input id="edit" class="what" type="text">
        </div>
        <div class="div1">
            <input class="submit" type="button" value="提交" onclick="submit()">
        </div>
    </div>
</body>
<script>
    function submit(){
        let containDiv = document.querySelectorAll('#edit')
        console.dir(containDiv)
        let from = containDiv[0].value
        let to = containDiv[1].value
        let message = containDiv[2].value
        console.log(from+'对'+to+'说'+message)
        // 创建div
        let nodeDiv = document.createElement('div')
        nodeDiv.className = 'div1'
        nodeDiv.innerHTML = from+'对'+to+'说'+message
        console.log(nodeDiv)
        // 尾插div
        let nodeparent = document.querySelector('.total')
        nodeparent.appendChild(nodeDiv)
    }
</script>
</html>
相关推荐
未来之窗软件服务13 分钟前
免费版酒店押金原路退回系统之【房费押金计算器】实践——仙盟创梦IDE
前端·javascript·css·仙盟创梦ide·东方仙盟·酒店押金系统
拾光拾趣录16 分钟前
常见 HTTP 请求头:从“为什么接口返回乱码”说起
前端·http
阿华的代码王国16 分钟前
【Android】卡片式布局 && 滚动容器ScrollView
android·xml·java·前端·后端·卡片布局·滚动容器
2025年一定要上岸23 分钟前
【pytest高阶】源码的走读方法及插件hook
运维·前端·python·pytest
姑苏洛言27 分钟前
答题抽奖活动小程序技术复盘
前端
砖头拍死你1 小时前
51单片机如何使用printf打印unsigned long的那些事
java·前端·51单片机
用户1512905452201 小时前
css —pointer-events属性_css pointer-events
前端
帅夫帅夫1 小时前
Axios 入门指南:从基础用法到实战技巧
前端
云边散步1 小时前
《校园生活平台从 0 到 1 的搭建》第四篇:微信授权登录前端
前端·javascript·后端
讨厌吃蛋黄酥1 小时前
React样式冲突终结者:CSS模块化+Vite全链路实战指南🔥
前端·javascript·react.js