js,jQuery获取当前时间,并显示打印

简易的效果
在这里插入图片描述
代码:

<style>
        div{
            width: 200px;
            height: 80px;
            background-color: #90EE90;
            margin: 10px 0 10px 0;
        }
    </style>
</head>
<body>
<textarea></textarea><br>
<button>发布</button><br>

<script>
    $(function () {
        $('button').on('click',function () {
            let t = new Date();
            let h = t.getHours();
            let m = t.getMinutes();
            let s = t.getSeconds();
            let T = h+"时"+m+"分"+s+"秒"+"来自xxx";

            let val = $('textarea').val();
            let template = `<div>
                                <span class="time">${T}</span><br>
                                <span class="text">${val}</span>
                            </div>`;
            $('body').append(template);
        })

    })
</script>
</body>
发布了37 篇原创文章 · 获赞 43 · 访问量 4924

猜你喜欢

转载自blog.csdn.net/printf_hello/article/details/104200710