Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Page2</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://code.jquery.com/jquery-1.11.1.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
    <style>
        * { font-size: 14px;}
        .write-box { width: 60%; padding: 14px 10px;}
        .btn-reset { width: 80px; padding: 14px 10px;}
    </style>
</head>
<body>
    <!--[if lte IE8]>
    <p class="browserupgrade">您的浏览器版本老的可笑,请到<a href="http://browsehappy.com/">这里</a>更新,以获取最佳的体验</p>
    <![endif]-->
    <h1>page2</h1>
    <input class="write-box" type="text" placeholder="请在此输入" value="" onchange=btnClick(this.value)>
    <div>send to page1:</div>
    <ul class="send-box"></ul>
    <div>receive from page1:</div>
    <ul class="receive-box"></ul>
    <script>
        var socket = null; //socket对象
        $(function () {
            socket = io.connect('http://localhost:8080');
            // socket.send('222');
            //连接成功返回的提示
            socket.on('message', function (json) {
                console.log("receive: " + json);
                $(".receive-box").append($('<li>').text(json));
            });
            //断开
            socket.on('DisconnectReq', function () {
                socket.emit('disconnect');
            });
        });
        //点击事件
        function btnClick(msg) {
            socket.emit("data", msg);
            console.log("send: " + msg);
            resInput(msg);
        }
        // 清空输入
        function resInput(msg) {
            $(".send-box").append($('<li>').text(msg));
            $(".write-box").val("");
        };
    </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
CC-catpro
0viewers