html如何运行js
html运行JS的方式有:通过引入外部的JS文件来调用,一般将JS写在一个外部文件中,封装起来,然后在调用,举个实例:
<html><head><style>#div1{width:460px;height:200px;position:absolute;}</style></head><scripttype='text/javascript'src='js文件的地址'></script><body><divid='div1'><p>我是测试文字</p></div> 2.在Js中通过<script></script>这个标签,将JS写在里面也是可以的,请看代码:
<html><head><style>#div1{width:460px;height:200px;position:absolute;}</style><script>varoDiv=document.getElementById('div1'
)varLet=Div.style.left;//上下的值,varRig=Div.style.top;</script></head><body><divid='div1'><p>我是测试文字</p></div></body></html>
javascript怎么操作socket
可以实现的
// 创建一个Socket实例
var socket = new WebSocket('ws://localhost:8080');
// 打开Socket
socket.onopen = function(event) {
// 发送一个初始化消息
socket.send('I am the client and I'm listening!');
// 监听消息
socket.onmessage = function(event) {
console.log('Client received a message',event);
};
// 监听Socket的关闭
socket.onclose = function(event) {
console.log('Client notified socket has closed',event);
};
// 关闭Socket....
//socket.close()
};
参数为URL,ws表示WebSocket协议。onopen、onclose和onmessage方法把事件连接到Socket实例上。每个方法都提供了一个事件,以表示Socket的状态。
还没有评论,来说两句吧...