图像未使用 DOM 操作更新
我正在尝试根据条件在两张图像之间切换。我正在考虑更改 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论