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