简易留言板

可以写入或删除内容

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
padding: 100px;
}
textarea {
width: 310px;
height: 45px;
border: 1px solid rgb(0, 0, 0);
font-size: 30px;
line-height: 45px;
outline: none;
resize: none;
}
ul {
margin-top: 50px;
list-style-type: none;
width: 310px;
height: 100vh;
background-color: aqua;
}
li {
width: 300px;
padding: 5px;
background-color: rgb(0, 0, 0);
color: rgb(255, 255, 255);
font-size: 14px;
margin: 15px 0;
}
button {
width: 154px;
height: 50px;
}
</style>
</head>
<body>
<textarea name="" id="" placeholder="请输入内容"></textarea><br>
<button id="button1">发布</button>
<button id="button2">删除</button>
<ul>
</ul>
<script>
var btn = document.getElementById('button1');
var text = document.querySelector('textarea');
var ul = document.querySelector('ul');
btn.onclick = function () {
if (text.value == '') {
alert('您没有输入内容');
return false;
} else {
var li = document.createElement('li');
li.innerHTML = text.value;
ul.insertBefore(li, ul.children[0]);
}
}
</script>
<script>
var ul = document.querySelector('ul');
var btn = document.getElementById('button2');
btn.onclick = function () {
if (ul.children.length == 0) {
this.disabled = true;
} else {
ul.removeChild(ul.children[0]);
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            padding: 100px;
        }

        textarea {
            width: 310px;
            height: 45px;
            border: 1px solid rgb(0, 0, 0);
            font-size: 30px;
            line-height: 45px;

            outline: none;
            resize: none;
        }

        ul {
            margin-top: 50px;
            list-style-type: none;
            width: 310px;
            height: 100vh;
            background-color: aqua;
        }

        li {
            width: 300px;
            padding: 5px;
            background-color: rgb(0, 0, 0);
            color: rgb(255, 255, 255);
            font-size: 14px;
            margin: 15px 0;
        }

        button {
            width: 154px;
            height: 50px;
        }
    </style>
</head>

<body>
    <textarea name="" id="" placeholder="请输入内容"></textarea><br>
    <button id="button1">发布</button>
    <button id="button2">删除</button>

    <ul>

    </ul>
    <script>
        var btn = document.getElementById('button1');
        var text = document.querySelector('textarea');
        var ul = document.querySelector('ul');
        btn.onclick = function () {
            if (text.value == '') {
                alert('您没有输入内容');
                return false;
            } else {
                var li = document.createElement('li');
                li.innerHTML = text.value;
                ul.insertBefore(li, ul.children[0]);
            }
        }
    </script>

    <script>
        var ul = document.querySelector('ul');
        var btn = document.getElementById('button2');
        btn.onclick = function () {
            if (ul.children.length == 0) {
                this.disabled = true;
            } else {
                ul.removeChild(ul.children[0]);
            }
        }
    </script>
</body>

</html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> * { margin: 0; padding: 0; } body { padding: 100px; } textarea { width: 310px; height: 45px; border: 1px solid rgb(0, 0, 0); font-size: 30px; line-height: 45px; outline: none; resize: none; } ul { margin-top: 50px; list-style-type: none; width: 310px; height: 100vh; background-color: aqua; } li { width: 300px; padding: 5px; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255); font-size: 14px; margin: 15px 0; } button { width: 154px; height: 50px; } </style> </head> <body> <textarea name="" id="" placeholder="请输入内容"></textarea><br> <button id="button1">发布</button> <button id="button2">删除</button> <ul> </ul> <script> var btn = document.getElementById('button1'); var text = document.querySelector('textarea'); var ul = document.querySelector('ul'); btn.onclick = function () { if (text.value == '') { alert('您没有输入内容'); return false; } else { var li = document.createElement('li'); li.innerHTML = text.value; ul.insertBefore(li, ul.children[0]); } } </script> <script> var ul = document.querySelector('ul'); var btn = document.getElementById('button2'); btn.onclick = function () { if (ul.children.length == 0) { this.disabled = true; } else { ul.removeChild(ul.children[0]); } } </script> </body> </html>

 

©造梦空间论坛 BY 长沙造梦空间网络科技有限公司
简易留言板-造梦空间论坛
简易留言板
此内容为付费阅读,请付费后查看
3积分
联系客服:tencent110tx
付费阅读
© 版权声明
THE END
喜欢就支持一下吧
点赞4 分享
Smash the waves would rather get in the way of the reef hill, also not willing to take a step back.
海浪宁可在挡路的礁山上撞得粉碎,也不肯后退一步
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容