倒计时
backbone.view 的作用是新建一个需要的dom对象,该dom对象只是backbone.view的一个属性。,每个backbone.view的实例
同理对于倒计时,正常(样式,内容修改)可以用一个函数对所有class=“all”的dom对象进行修改,但如果是倒计时,就会不准确,必然会有每次前面的div先执行倒计时函数,后面的div后执行倒计时函数的过程。
所以,每个class=“all”的dom对象都应该拥有自己的倒计时事件,作为一个单独的view的实例。
define(function (require, exports, moudule) {
var $ = require("jquery")
var _ = require("underscore")
var juicer = require("juicer")
var class_function = function () {
this.create_dom.apply(this, arguments)
this.initialize.apply(this,arguments)
}
var extend = function (protoProps, staticProps) {
var parent = this
var child
child = function () {
return parent.apply(this, arguments)
}
_.extend(child, parent, staticProps);
var Surrogate = function () {
this.constructor = child;
};
Surrogate.prototype = parent.prototype
child.prototype = new Surrogate;
if (protoProps) _.extend(child.prototype, protoProps);
/**/
return child
}
class_function.extend=extend
_.extend(class_function.prototype, {
initialize:function(){},
create_dom:function (number) {
this.name=number
min=parseInt(number/60)
second=number%60
ms=
this.$el = $("<div class='all'>"+min+":"+second+"</div>")
$("body").append(this.$el)
this.Event(this.$el)
},
Event:function () {
var $this = this
this.$el.click(function () {
$this.count(this)()
})
},
count:function (obj) {
var $this = this
return function () {
$this.name = $this.name - 1
min=parseInt($this.name/60)
second=$this.name%60
var temp = arguments.callee
$(obj).html(min+":"+second)
if ($this.name > 0) {
window.setTimeout(function () {
temp()
}, 1000)
}
}
}
})
var newtime=class_function.extend({
Event:function(){
var $this = this
this.$el.click(function () {
alert($this.$el.html())
$this.count(this)()
})
}
})
var h4=new newtime(15*100)
var h=new class_function(15*60)
var k=new class_function(10*60)
var k1= new class_function(12*60)
})

浙公网安备 33010602011771号