zoukankan      html  css  js  c++  java
  • 私聊前端页面的编写

    <p> 输入发送的信息 <input type="text" id="send_id">
        <button onclick="send_func()">发送</button>
    </p>
    
    <div id="data_id">
    
    
    </div>
    
    </body>
    <script type="application/javascript">
    
        var ak=null;
        function lg_func() {
    
            //拿到input 登录 的用户名
            var username = document.getElementById('login_id').value;
    
    
    
            ak = new WebSocket("ws:127.0.0.1:5000/ak/"+username);
        ak.onopen = function () {
    
            alert("登录成功")
        };
    
        ak.onmessage = function (message) {
    
            console.log(message.data);
    
            var msg = JSON.parse(message.data);
    
    
             //创建一个标签
            var p = document.createElement('p');
    
            p.innerText = msg.from_user + ":"+msg.msg;
    
            document.getElementById('data_id').appendChild(p);
    
        };
    
        }
    
        function send_func() {
    
            var msg = document.getElementById('send_id').value;
            var arther = document.getElementById('arther_id').value;
            msg_dic = {
    
                'arther': arther,
                'msg':msg
            };
    
            ak.send(JSON.stringify(msg_dic));
    
            var p = document.createElement('p');
            p.innerText = msg + ':我';
            document.getElementById("data_id").appendChild(p);
        }
    
    
    </script>
    </html>
  • 相关阅读:
    游记&退役记
    Nothing to say
    学习知识点的比较好的blog
    计划做题列表
    后缀自动机小专题
    复数
    FFT学习
    P2900 [USACO08MAR]土地征用Land Acquisition
    # 数位DP入坑
    Hdu 4035 Maze(概率DP)
  • 原文地址:https://www.cnblogs.com/LMTlmt/p/11553719.html
Copyright © 2011-2022 走看看