【问题标题】:location setting of images after a new image response新图像响应后图像的位置设置
【发布时间】:2015-07-09 12:29:48
【问题描述】:

我必须制作一个需要每 1 小时动态显示图像的网页。我使用 jquery、JavaScript 和一个 servlet 添加了 1 个图像。

我想添加另一张图片,并将上一张图片的位置更改为+1。怎么做? 函数 Onload(){

    $.get("ImageContent4", function(data) {

    document.getElementById("image1").src=data;
    //document.getElementById("image2").src=data;
    });
}
window.onload=Onload();
</script>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor="#4a7d49">
<center>
<h2 style=background-color:red>India Meteorological Department</h2>
</center>

<img id="image1" src=" " style="width:128px ; height:228px";>
</body>
</html>

这里的 ImageContent4 是一个 servlet,它在页面加载后发送图像作为响应。

【问题讨论】:

  • 请提供一些代码来告诉我们您到目前为止尝试过什么并且遇到了困难
  • 请向我们展示您到目前为止所做的代码?

标签: javascript jquery html image servlets


【解决方案1】:

您可以简单地替换图像的“src”属性。使用 jQuery ...

$(function() {
    $("img").attr("src", <put the new url here>);
});

您可能希望在交换源之前预加载图像,但这是一个不同的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多