<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
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |