实现的一个网页版的简易表白墙

实现的一个网页版的表白墙

实现效果

代码截图

相关代码

javascript 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="container">
        <h1>表白墙</h1>
        <P>输入相关信息,点击提交后将会展示在表格中</P>
        <div class="div1">
            <span>谁:</span><input type="text" class="edit">
        </div>
        <div class="div1">
            <span>对谁:</span><input type="text" class="edit">
        </div>
        <div class="div1">
            <span>说:</span><input type="text" class="edit">
        </div>
        <div class="div1">
            <input type="button" value="提交" class="submit" onclick="Submit()">
        </div>
    </div>
</body>
<style>
    * {
        margin: 0px;
        padding: 0px;
    }
    .container {
        width: 400px;
        margin: 0 auto;
    }
    h1 {
        text-align: center;
        margin-bottom: 20px;
        margin-top: 40px;
    }
    p {
        text-align: center;
        color: gray;
        line-height: 63px;
    }
    .div1 {
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .edit {
        margin-bottom: 20px;
        width: 200px;
        height: 30px;
    }
    span {
        width: 50px;
        margin-bottom: 20px;
    }
    .submit {
        background-color: rgb(255, 136, 0);
        color: white;
        width: 254px;
        height: 40px;
        border: none;
        border-radius: 5px;
    }
    .submit:active {
        background-color: gray;
    }

</style>
<script>
    function Submit() {
        let edits = document.querySelectorAll('.edit')
        let from  = edits[0].value
        let to  = edits[1].value
        let message = edits[2].value
        if(from == "" || to == "" || message == "") {
            return
        }
        let div = document.createElement('div')
        div.className = 'div1'
        div.innerHTML =   from + " 对 " + to + "说:" + message 
        let container = document.querySelector('.container')
        container.appendChild(div)
        for(i = 0; i < edits.length; i++) {
            edits[i].value = "";
        }
}
</script>
</html>
相关推荐
excel2 小时前
ES6 中函数的双重调用方式:fn() 与 fn\...``
前端
可乐爱宅着2 小时前
全栈框架next.js入手指南
前端·next.js
你的人类朋友3 小时前
什么是API签名?
前端·后端·安全
会豪5 小时前
Electron-Vite (一)快速构建桌面应用
前端
中微子5 小时前
React 执行阶段与渲染机制详解(基于 React 18+ 官方文档)
前端
唐某人丶5 小时前
教你如何用 JS 实现 Agent 系统(2)—— 开发 ReAct 版本的“深度搜索”
前端·人工智能·aigc
中微子5 小时前
深入剖析 useState产生的 setState的完整执行流程
前端
遂心_6 小时前
JavaScript 函数参数传递机制:一道经典面试题解析
前端·javascript
小徐_23336 小时前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
RoyLin6 小时前
TypeScript设计模式:适配器模式
前端·后端·node.js