我有以下节点服务器和index.html文件,当我在浏览器中的多个选项卡或窗口中打开index.html文件时,当我单击按钮时,它会显示按钮,单击所有打开的选项卡和窗口但按钮颜色不会在所有选项卡中更改,只会在单击按钮的选项卡中更改。
app.js
content.Content = new ExcelReportVM();
的index.html
const io = require('socket.io')(3000);
io.on('connection', function (socket) {
console.log('a client has connected');
socket.on('clicked', function() {
io.emit('clicked');
});
});
console.log('socket.io server started at port 3000');
答案 0 :(得分:0)
将“onClickHandler”调用添加到“clicked”事件回调中,例如:
socket.on('clicked', function() {
var button = document.getElementById('button');
console.log('clicked');
document.getElementById("alert").innerHTML = "send clicked";
onClickHandler(button);
});