西门子网络服务器在 html 中使用 JavaScript 更改图像

发布于 2025-01-16 08:04:48 字数 443 浏览 2 评论 0原文

我尝试使用 javascript 根据真/假条件动态更改 html 页面中的图片。 如果变量为 0,则应在 html 页面中显示另一张图片;如果为 1,则应显示另一张图片。

项目中有很多图片需要更改,我需要一个可以执行此应用程序的功能。但我不知道是否可以使用单个函数来完成,或者我应该为每个变量使用一个函数。

西门子网络服务器是否通过键入 :="X": 自动应用变量更改: 当 x 为 0 而不是 :="X" 时:数字 0 被替换;当 x 为 1 而不是 :="X" 时:数字 1 被替换。 我熟悉 html 编码以及如何使用图像名称并在图像名称后添加 0 或 1 来更改图片。 例如,我将一张图片命名为 stop0.png ,将另一张图片命名为 stop1.png 。现在在 html 代码中我输入 stop:="X":.png 这样图片会根据变量 x 变化 但这种方法需要刷新页面才能显示变化。我想以最简单的方式做到这一点,而无需刷新页面。

Im trying to dynamically change a picture in html page according to a true/false condition using javascript.
If the variable is 0 an image and if it was 1 another picture should be shown in html page.

There are many pictures in a project that need to be changed i need a function that can do this application. But i dont know if it can be done with a single function or i should use a function for each variable.

Is siemens webserver the variable change is applied automatically by typing :="X":
when x is 0 instead of :="X": the number 0 is replaced and for the 1 instead of :="X": the number 1 is replaced.
Im familiar with html coding and how to change the picture using the image name and adding 0 or 1 after image name.
For example i name a picture stop0.png and another picture stop1.png . now in the html code i type stop:="X":.png in this way picture changes according to variable x
But this method needs the page to be refreshed to show the change. I want to do this in the easiest way possible without page refresh.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多像笑话 2025-01-23 08:04:48

hmi 应该设计在一个页面中(例如名为 test.htm),另一个带有以下代码的 html 页面将每秒更新“test.htm”中的所有内容。

<!DOCTYPE html>
<html>
<body>

<div id="demo">
  <h2>auto update page</h2>
</div>
<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "test.htm", true);
  xhttp.send();
}
setInterval("loadDoc()", 1000);
</script>
</body>
</html>

hmi should be designed in one page (for example named test.htm) and another html page with following code would update every thing in "test.htm" every second.

<!DOCTYPE html>
<html>
<body>

<div id="demo">
  <h2>auto update page</h2>
</div>
<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "test.htm", true);
  xhttp.send();
}
setInterval("loadDoc()", 1000);
</script>
</body>
</html>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文