对话框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        *{
            margin: 0;
            padding: 0;
        }

        body{
            width: 1000px;
            margin:0 auto;
            display: flex;
            justify-content: space-around;
        }

        h1{
            width: 300px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            background: skyblue;
            border: 1px solid gray;
        }

        ul{
            list-style: none;
            width: 300px;
            height: 500px;
            background: lightsteelblue;
            border: 1px solid gray;
            border-top: none;
            overflow-y: auto;
        }

        input{
            width: 250px;
            height: 30px;
            margin-top: 20px;
        }

        li{
            width: 260px;
            margin:0 auto;
        }

    </style>
</head>
<body>
<div id="boxa">
<h1>小A</h1>
<ul class="frame">

</ul>
<input type="text">
<button id="btna">发送</button>
</div>

<div id="boxb">
<h1>小B</h1>
<ul class="frame">

</ul>
<input type="text">
<button id="btnb">发送</button>
</div>

<script>

        var ArrBox=document.getElementsByTagName("div");
        var BtnA=ArrBox[0].getElementsByTagName("button")[0];
        var BtnB=ArrBox[1].getElementsByTagName("button")[0];
        var Ipt=ArrBox[0].getElementsByTagName("input")[0];
        var IptB=ArrBox[1].getElementsByTagName("input")[0];
        var oUl=ArrBox[0].getElementsByTagName("ul")[0];
        var bUl=ArrBox[1].getElementsByTagName("ul")[0];

        BtnA.onclick=fn;
        Ipt.onkeydown=function(ev){
            var Event=ev||window.event;
            if(Event.ctrlKey&&Event.keyCode==13){
                fn();
            }
        }

        function fn(){
                if(Ipt.value==""){
                    alert("内容不能为空")
                }

                else{
                    var myDate=new Date();
                    var Month= myDate.getMonth()+1;
                    var time=myDate.getFullYear() + "年"
                            +Month + "月"
                            +myDate.getDate() + "日" + "&nbsp;"
                            +"星期"+myDate.getDay()+"&nbsp;"
                            +myDate.getHours()+":"
                            +myDate.getMinutes() + ":"
                            +myDate.getSeconds();

                    var oli=document.createElement("li");
                    var oli2=document.createElement("li");
                    var oli3=document.createElement("li");
                    var oli4=document.createElement("li");

                    oli.innerHTML=Ipt.value+"<br/>";
                    oli2.innerHTML=time+"<br />";
                    oli3.innerHTML=oli.innerHTML;
                    oli4.innerHTML=oli2.innerHTML;
                    Ipt.value="";
                    oli.style.textAlign="right";
                    oli3.style.textAlign="left";
                    oli2.style.textAlign="center";
                    oli4.style.textAlign="center";
                    oUl.appendChild(oli);
                    oUl.insertBefore(oli2,oli);
                    bUl.appendChild(oli3);
                    bUl.insertBefore(oli4,oli3);
                }
            }

        BtnB.onclick=bn;

        IptB.onkeydown=function(ev) {
            var Event = ev || window.event;
            if (Event.ctrlKey && Event.keyCode == 13) {
                bn();
            }
        }

            function bn(){
            if(IptB.value==""){
                alert("内容不能为空")
            }

            else{
                var myDate=new Date();
                var Month= myDate.getMonth()+1;
                var time= myDate.getFullYear() + "年"
                        +Month + "月"
                        +myDate.getDate() + "日" + "&nbsp;"
                        +"星期"+myDate.getDay()+"&nbsp;"
                        +myDate.getHours()+":"
                        +myDate.getMinutes() + ":"
                        +myDate.getSeconds();

                var oli=document.createElement("li");
                var oli2=document.createElement("li");
                var oli3=document.createElement("li");
                var oli4=document.createElement("li");
                oli.innerHTML=IptB.value+"<br/>";
                oli2.innerHTML=time+"<br />";
                oli3.innerHTML=oli.innerHTML;
                oli4.innerHTML=oli2.innerHTML;
                IptB.value="";
                oli.style.textAlign="left";
                oli3.style.textAlign="right";
                oli2.style.textAlign="center";
                oli4.style.textAlign="center";
                oUl.appendChild(oli);
                oUl.insertBefore(oli2,oli);
                bUl.appendChild(oli3);
                bUl.insertBefore(oli4,oli3);
            }
        }



</script>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值