2021-05-27

                                                                      简单的聊天框

1.源代码:

<body>

<div class="beijing">

     <div class="dingbu"><i></i></div>

    <div class="neishe" id="nvhai">

     </div>

     <div class="wenben">

         <button class="t1" id="qiehuan">boy</button>

         <input type="text" class="t3" id="shuru">

         <button class="t2" id="fasong">┗( ▔, ▔ )┛发送</button>

     </div>

</div>

<script src="js.js"> </script>

</body>

2.css样式

    *{

            margin: 0;

            padding: 0;

            user-select: none;

            outline: none;

        }

        .beijing{

            width: 700px;

            height: 625px;

            margin: 30px auto 0;

            background-color: #1B629A;

        }

        .beijing .dingbu{

            width: 100%;

            height: 30px;

        }

        .dingbu i{

            display: block;

            width: 20px;

            height: 20px;

            margin: 0px 0px 0px 357px;

            border-radius: 32px;

            background-color:#000000;

        }

        .neishe{

           

            width: 600px;

            height: 534px;

            margin: 0px 0px 0px 50px ;

            background: url("聊天stem/屏幕截图 2021-03-10 152611.png") no-repeat;

            background-size: 621px;

        }

        .wenben{

            margin: 10px 0px 0px 50px ;

            width: 600px;

            height: 50px;

        }

        .wenben .t1{

            width: 50px;

            height: 40px;

            border-radius:50px;

            background-color: darkseagreen;

        }

        .wenben .t3{

            width: 450px;

            height: 40px;

            font-size: 20px;

            background-color: aqua;

           

        }

        .wenben .t2{

            height: 40px;

            border-radius: 21px 21px 0px 0px;

            background-color: blueviolet;

        }

        .neishe div{

            clear: both;

            display:block;

            padding: 10px 50px ;

            margin: 11px 12px ;

            background-color: cadetblue;

            border-radius: 25px;

        }

3.Js代码

window.οnlοad=function(){

    var a=document.getElementById("qiehuan");

    var b=document.getElementById("shuru");

    var c=document.getElementById("fasong");

    var d=document.getElementById("nvhai")

   

    a.οnclick=function(){

        if(a.innerText=="boy"){

            a.innerText="gril"

        }else{

            a.innerText="boy"

        }

    }

     c.οnclick=function(){

         if(a.innerText=="boy"&&b.value!==""){

         var d=document.getElementById("nvhai");

         var div=null;

         div=document.createElement("div");

         div.innerText=b.value;

         d.appendChild(div);

         div.style.float="left";

         b.value="";

         }else if(a.innerText=="gril"&&b.value!==""){

            var d=document.getElementById("nvhai");

            var div=null;

             div=document.createElement("div");

             div.innerText=b.value;

             d.appendChild(div);

             div.style.float="right"

             b.value="";

         }else{

             return false;

         }

         if(d.childElementCount>7){

             var e=document.getElementById("nvhai").firstChild;

                d.removeChild(e);//删除元素节点

         }

     }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值