如何将document.write()与文件一起使用而不是文本?
我正在使用socket.io创建类似于针对人类卡的派对游戏。我只是想知道如何在新游戏开始时不必将所有数据发送到新页面,而无需将所有数据发送到新页面。我当时想只是更改HTML的身体,但请留在同一页面上,以便JavaScript无法重置,我仍然可以访问所有播放器信息。
我遇到使用document.write()
,但这似乎只接受字符串参数。有没有办法做这样的事情document.write(game.html)
。
关于如何解决这个问题的任何想法,也许是在JavaScript文件之间传递信息的一种更好的方法,而无需每次加载新页面时都会发布数据?我尝试通过帖子发送数据,但是这使得所有内容保持一致变得更加困难。
ps这是我第一次使用node.js,socket.io,javascript等正确地做任何事情,所以我可以问一个愚蠢的问题。
I am using socket.io to create a party game similar to cards against humanity. I am just wondering how I can keep the players name and score etc without having to send all the data to a new page when new games begin. I was thinking to just change the body of the html but stay on the same page so the javascript doesnt reset and I can still access all the players information.
I came across using document.write()
however this appears to only accept a string parameter. Is there a way to do something like this document.write(game.html)
.
Any ideas on how to go about this, maybe a better way to pass information between javascript files without having to post the data each time a new page is loaded? I have tried sending the data with post however it makes it far more difficult to keep everything consistent.
P.S This is the first time I have properly made anything with node.js, socket.io, javascript etc. So I could be asking a stupid question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从事件侦听器中获取
socket.io
数据后,您可以使用QuerySelector()
或任何其他DOM操纵方法来显示DOM中的数据。这样的东西?HTML
JS
Once you get
socket.io
data from an event listener, you can usequerySelector()
or any other DOM manipulation method to show the data in the DOM. Something like this?HTML
JS