我很抱歉问这样一个初学者问题,但是我要添加什么来在html上显示它?
DispatcherTimer timer1 = new DispatcherTimer();
private void button1_Click(object sender, RoutedEventArgs e)
{
timer1.Interval = new TimeSpan(0, 0, 0, 1);
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
int tik = 60;
void timer1_Tick(object sender, EventArgs e)
{
Countdown.Text = tik + " Seconds Remaining";
if (tik > 0)
tik--;
else
Countdown.Text = "Times Up";
}
答案 0 :(得分:1)
创建一个div
或其他容器以在您的html中存储String。例如,在您的html中,您可以添加:
<div id="time-text"></div>
然后在你的js中,可能在Tick方法中,你可以添加:
<强> jQuery的:强>
$('#time-text').html(Countdown.Text);
或
纯JavaScript:
document.getElementById('#time-text').innerHTML = Countdown.Text;