留言板

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言栏</title>
    <!-- <link rel="stylesheet" href="./reset.css"> -->
    <!-- 引入css样式表 -->
    <link rel="stylesheet" href="./留言栏.css">
    
</head>

<body>
    <h1>留言框</h1>
    <!-- 留言框 -->
    <form>
        <input type="text" id="name"  placeholder="请输入您的姓名!">
        <br />
        <input type="text" id="message" placeholder="请写下您的留言......">
        <!-- 设置文本框的提示框 -->
        <div class="tips">
            文明用语,从我做起。
        </div>
        <br/>
        <hr/>
        <input type="button" class="button" οnclick="fun()" value="留言">
    </form>

    <div class="message-text"> 
        <div>留言列表:</div>
    </div>

    <div id="message-text"></div>

    <!-- 引入脚本 -->
    <script src="./留言栏.js"></script>
</body>
</html>
body{
    background-color: #17A6E0;
}

h1{
    margin-left: 120px;
    color: rgb(78, 76, 76);
}
form{
    width: 222px;
    margin: 30px 0 20px 60px;
    border: 1px solid #ccc;
    padding-bottom: 20px;
    position: relative;
    border-radius: 5px;
    background-color: #fff;
    box-shadow: 3px 2px 5px 0.2px rgba(0, 0, 0, 0.52);
}
form span{
    margin-left: 10px;
}

form input{
    display:block;
    /* margin:0  auto; */
    
}

form #name{
    margin:0  auto;
    margin-top:20px ;
    width:190px;
}

form #message{
    margin:0  auto;
    height: 90px;
    margin-bottom: -6px;
    width:190px;
    
}

form .tips{
    width: 120px;
    height: 20px;
    display:none ;
    font-size: 12px;
    border:1px #ccc solid;
    color: #ccc;
    text-align: center;
    border-radius: 10px;
    /* 开启绝对定位 */
    position: absolute;
    top: 70px;
    left: 50px;
}

form #message:focus,#name:focus{
    border:.5px solid #B5DEF2;
}

form #message:hover+.tips {
    display: block;
}
form #message:focus +.tips {
    display: none;
}

form .button{
    margin-left:148px;
    border-radius: 5px;
    border: none;
    color: rgb(124, 120, 120);
    font-size: 16px;
}

.message-text{
    height: 20px;
    line-height: 20px;
    background-color: #ccc; 
    border-radius: 10px;
}
.message-text div{
    margin-left: 30px;
    color: rgb(124, 120, 120);
}

/* #message-text{
    background-color:#ccc ;
} */
#message-text p{
    font-family: 仿宋;
    font-size: 16px;
    color: rgb(20, 9, 9);
}


function fun(){
    //获取文本框内容
    var name1= document.getElementById('name').value;
    var message= document.getElementById('message').value;
    //判断输入框的内容并提升
    if(name1===''||message===''){
        alert("姓名和留言不能为空,请重新输入!");
    }
    else{
        //创建文本节点
        var str=document.createTextNode('【姓名:'+name1+'】\n 发表:'+message+'\n【'+getTime()+'】');
        //创建子标签节点
        var messageText=document.createElement('p');
        messageText.appendChild(str);
        //创建容器节点
        var childMessage=document.getElementById('message-text');
        childMessage.appendChild(messageText); 
    }
        //清空文本内容
        document.getElementById('name').value=null;
        document.getElementById('message').value=null;
}
// 获取当前时间
function getTime(){
        var now = new Date();//获取当前的时间
        // document.write(now);//初始的时间格式
        //获取年月日和时间
        var year =now.getFullYear();
        var month=now.getMonth()+1;
        var ri=now.getDate();
        var hour=now.getHours();
        var minute=now.getMinutes();
        var second=now.getSeconds();
        
    //格式
    var str=year+"."+month+". "+ri+". "+hour+": "+minute+": "+second+" ";
    return str;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值