这是我的应用jsfiddle
此应用程序是一个问题测试。 它具有以下功能:
现在我遇到第3项问题,我不知道如何clearInterval计时器。 谁能帮我!谢谢!
var TimerView = Backbone.View.extend({
el: $("#time-value"),
initialize: function () {
var self = this;
//console.log(this.model.get("seconds"));
//this.current = (new Date()).getSeconds();
var _t = new Date();
this.end = _t.setSeconds(_t.getSeconds() + Number(this.model.get("seconds")));
// this.end = (new Date(this.model.getTime() + this.model.seconds * 1000)).getTime();
this.model.on('change', this.render(), this);
},
cdInterval: '',
startCountdown: function () {
var self = this;
console.log('start countdown');
this.cdInterval = window.setInterval(function () {
self.render();
}, 10);
},
stopCountdown: function () {
console.log('stop countdown222');
clearInterval(this.cdInterval);
},
render: function () {
var end = this.end,
now = (new Date()).getTime(),
_second = 1000,
_minute = _second * 60,
diff = end - now;
if (diff <= 0) {
this.stopCountdown();
// app.navigate('qid/2', { trigger: true });
this.$el.html(" 00 : 000 ");
/*var result = new Result({
qid: '',
status: 3
});*/
app.result.set({
qid: app.id,
status: 3
});
/*(new PopupView({
model:app.result
})).render();*/
return false;
}
// some code....
}
}); jsfiddle