时间:2021-07-01 10:21:17 帮助过:32人阅读
嗯,谢谢哦,方案可行。不过再问下,html控件的src可以动态切换么?我这样写的代码,不行。
System.Timers.Timer timer = new System.Timers.Timer();
private static int count;
protected void Page_Load(object sender, EventArgs e)
{
count = 0;
Picture();
Timer_Start();
}
protected void Timer_Start()
{
timer.AutoReset = true;
timer.Enabled = true;
timer.Interval = 5000;
timer.Elapsed += new System.Timers.ElapsedEventHandler(this.Picture_Show);
}
protected void Picture_Show(Object sender, ElapsedEventArgs e)
{
count = (count + 1) % 6;
switch (count)
{
case 0: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/UPS.jpg");
break;
case 1: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/电量仪.jpg" + "?temp=" + DateTime.Now.Millisecond.ToString());
break;
case 2: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/空调.jpg");
break;
case 3: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/门禁.jpg");
break;
case 4: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/漏水.jpg");
break;
case 5: this.imgkt.Src = this.imgkt.ResolveClientUrl("image/温湿度.jpg");
break;
default:
break;
}
}
protected void Picture()
{
this.imgkt.Src = this.imgkt.ResolveClientUrl("image/漏水.jpg");
}
求指教,该如何写代码才能实现img背景的动态切换。