var data = [{"名称":"小明"},{"名称":"小余"}] var client = new WebSocket('ws://localhost:19730') , timer_0 = null client.onopen = function (e) { console.log('链接成功') timer_0 = self.setInterval('Clock_0()', 1000) } client.onclose = function (e) { console.log('链接断开') timer_0 = self.clearInterval(timer_0) } function Clock_0() { client.send(JSON.stringify(data)) console.log('定时器_0') }