我有两张图片img0.png和img1.png。我想根据bool变量重新加载图像。
我试过了
<script type="text/javascript">
$(document).ready(function(){
$.ajaxSetup({ cache: false });
setInterval(function() {
d = new Date();
$("#abc1").attr("src", "images/img:="status":.png?"+d.getTime());
},1000);
});
</script>
其中:=&#34; status&#34;:是我从PLC获得的bool变量。
当bool变量发生变化时,需要重新加载整页以刷新图像。是否可以在不刷新的情况下重新加载它?
编辑:
问题解决了。
setInterval(function() {
$.get("variable.htm", function(result){
$("#abc1").attr("src", "images/img" + result + ".png");
});
},1000);
其中variable.htm包含:=&#34; status&#34;:only。 感谢您的评论。