class Greeter
{
element: JQuery;
span: JQuery;
timerToken: number;
constructor(element: JQuery)
{
this.element = element;
this.span = $("<span/>");
this.element.append(this.span);
}
start()
{
this.timerToken = setInterval(() => this.span.html(new Date().toUTCString()), 500);
}
stop()
{
clearInterval(this.timerToken);
}
}
$(function ()
{
var greeter = new Greeter($("#content"));
// greeter.start();
$("#start").click(greeter.start);
$("#stop").click(greeter.stop);
});
我点击按钮提示获取不到span元素。如果直接采取greeter.start()可以正确执行,这是为什么呢?