javascript - 如何为所有查看者更新 html 页面?

标签 javascript html

基本上,我想用最后一个提交表单的人的姓名来更新页面。我有以下代码,但我只能让它在一台设备上更新。当从其他设备查看该页面时,它没有更新的名称。

 <form name="leds" id="ledSend" method="get" target="_blank" action="https://agent.electricimp.com/Fk43xPMkSrWF">
Lamp Control: <input type="radio" name="led" value="0" checked>Off
              <input type="radio" name="led" value="1">On<br>
How long should the Lights stay on? <input type="text" name="timer" value="10">seconds<br>
Your name? For Our Records <input id="name" type="text" name="user" placeholder="Your name here"><br>
<br>
<input type="submit" value="Update!" onclick="updateTable();"/>

</form>

<p id="last"></p>
<script>
 function updateTable(){
 document.getElementById("last").innerHTML =document.forms['leds'].elements[3].value;
 alert(document.forms['leds'].elements[3].value+", You are about to change the Lights! Beware that      there is about a 30 second delay on the live stream.");
 }
 </script>
 </html>

最佳答案

当您像这样使用 JavaScript 时(例如,为元素设置值),您仅更改查看该页面的一个工作站上的值。

您需要在服务器上建立某种数据存储,Web 浏览器可以将数据推送到其中并从中检索数据。例如,这可能位于服务器的内存中(短期且易失)或数据库管理系统(长期持久性)。

关于javascript - 如何为所有查看者更新 html 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27085979/

相关文章:

html - 什么应该使用 bgcolor 或 background-color?

html - 如何摆脱细节元素内部元素下方的空间

html - 对所有 div 应用 clearfix 以防止容器崩溃

jquery - 创建输入作为输入的 child

javascript - 如何将jquery值传递给codeigniter中的php模型函数

javascript - 在 React 中将空值设置为数字文本框

javascript - 如何使用 jQuery 更改新创建元素的属性

javascript - 如何获取Referrer URL的标题

javascript - 如何将分层 csv(分号分隔)转换为多维数组

javascript - Internet Explorer 8 事件因透明 parent 而失败