想显示导入文件进度,js实现了一个导入耗费时间的效果,但是想将其封装成面向对象的,可是封装之后没有正常运行,js 面向对象能力不够啊,不知道代码是啥原因,setinterval没有间隔时间运行,只运行了一次,请高手指导一下原因,谢谢啦!
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>新增属性值</title> <script type="text/javascript" src="jquery-1.10.2.min.js"></script> </head> <body> <div id="importInfo"></div> <input type="button" onclick="inportProcesser.Start()" value="开始"> <input type="button" onclick="inportProcesser.Close()" value="结束"> <script> function Progresser(intervalms, intervalHandle) { this.intervalMs = intervalms; this. totalIntervalMs = 0; this. timer=null; this.Oninterval = intervalHandle; } Progresser.prototype = { constructor: Progresser, Start: function () { //console.log("Start totalIntervalMs:" + this.totalIntervalMs); this.timer = setInterval( this.IntervalHandle() , this.intervalMs); //console.log("Start timer:" + this.timer); }, Close: function () { //console.log("Close totalIntervalMs:" + this.totalIntervalMs); if (this.timer != null) { //console.log("Close timer:clearInterval pre" + this.timer); clearInterval(this.timer); //console.log("Close timer:clearInterval next" + this.timer); } this.totalIntervalMs = 0; } , IntervalHandle: function () { this.totalIntervalMs += this.intervalMs ; //console.log("IntervalHandle totalIntervalMs:" + this.totalIntervalMs); this.Oninterval(this.totalIntervalMs); //console.log("IntervalHandle timer:" + this.timer); } } var inportProcesser = new Progresser(500, importing2); function importing2(totalIntervalMs) { var second = (totalIntervalMs / 1000.0).toFixed(1); console.log("seconds:" + second + "s.."); } </script> </body> </html>
紫衣仙女
慕尼黑5688855
holdtom
相关分类