图像未使用 DOM 操作更新

发布于 2025-01-12 07:13:14 字数 917 浏览 3 评论 0原文

我正在尝试根据条件在两张图像之间切换。我正在考虑更改 img 标记的 src 。 我可以更改 src 但在网页上图像未更新。

有人可以指出应该在哪里使用或更新什么吗?

这是我的 JS 代码 ->

success: function(data){
        if(data.status == 200){
          if(data.message == "Liked"){
            document.getElementById("like_image_state_change").src="{% static 'FrontEnd1/Static_Images/CovrPage_Like_R.png' %}";

          } 
          else if(data.message == 'Like Removed'){
            document.getElementById("like_image_state_change").src="{% static 'FrontEnd1/Static_Images/CovrPage_Like_W.png' %}";
            console.log(document.getElementById("like_image_state_change"));
          }
        }
        else{
          console.log('wrong');
        }
      }
    });

在这里,当我在“like Removed”中控制台 document.getElementById 时,我可以看到图像的更新后的 src,但图像在网页上仍然相同。

PS->我使用的后端是 DJango。 (如果重要的话)

I am trying to toggle between 2 images based on a condition. I am thinking to change the src of img tag.
I am able to change the src but on the webpage the image is not getting updated.

can someone point out where or what should be used or updated.

Here is my JS code ->

success: function(data){
        if(data.status == 200){
          if(data.message == "Liked"){
            document.getElementById("like_image_state_change").src="{% static 'FrontEnd1/Static_Images/CovrPage_Like_R.png' %}";

          } 
          else if(data.message == 'Like Removed'){
            document.getElementById("like_image_state_change").src="{% static 'FrontEnd1/Static_Images/CovrPage_Like_W.png' %}";
            console.log(document.getElementById("like_image_state_change"));
          }
        }
        else{
          console.log('wrong');
        }
      }
    });

Here when I console the document.getElementById in 'like Removed' I could see the updated src for the Image but the Image is still the same on the webpage.

PS -> The backend I am using is DJango. (if it matters)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文