标签:btn val var nec nop oct echo fun data
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input id="sendTxt" type="text">
<button id="sendBtn">发送</button>
<div id="recv"></div>
<script type="text/javascript">
var websocket = new WebSocket("ws://echo.websocket.org/");
websocket.onopen = function(){
console.log(‘websocket open‘);
document.getElementById("recv").innerHTML = "Connected";
}
websocket.onclose = function(){
console.log("websocket close");
}
websocket.onmessage = function(e){
console.log(e.data);
document.getElementById("recv").innerHTML = e.data;
}
document.getElementById("sendBtn").onclick = function()
{
var txt = document.getElementById("sendTxt").value;
websocket.send(txt);
}
</script>
</body>
</html>
标签:btn val var nec nop oct echo fun data
原文地址:http://www.cnblogs.com/lvqi/p/7851437.html