task任务使用、js定时!!!

本文介绍了一个使用ExtJS实现的定时任务案例,该案例中包含了一个每小时执行一次的任务,以及一个用于倒计时并在计时结束后自动保存报表数据的功能。通过设置定时器,系统会在指定的时间间隔后提醒用户并自动执行保存操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

没什么别的 只是想记录一下 不喜勿喷!!!

客户提出新需求,报表录入数据的时候每隔段时间页面弹出提示框,计时5秒,5秒后自动保存报表数据。

页面初始化的时候开始计时

//Extjs 定时任务
        var task = {
            run: function () {
                //一小时后需要执行的方法
                var tbar = Ext.getCmp('tbarYearDataReportSpread');
                App.ReportCommon.CountDown(me, tbar, "Y");
            },
            interval: 3600000,//计时一小时(毫秒级)
        };
        var task1 = new Ext.util.TaskRunner();
        task1.start(task);

一小时后执行js的倒计时保存,设置为一秒执行一次,js的这个函数运行完成后需要单独停止一下才可以clearInterval()  不然一直重复循环.  
//倒计时  
            var s = 4;
            var timer = window.setInterval(function () {
                if (s < 0) {
                    //关闭弹出框
                    CountDownWindow.close();
                    //停止js计时函数
                    clearInterval(timer);
                    //倒计时完成执行的方法
                    App.ReportCommon.TemporaryReportData(me, tbar, type);
                    //div清空
                    var str = '';
                    $(document.getElementsByName("TimeCount")).html("" + str + "");
                } else {
                    //div赋值
                    var str = '<h4 style="margin-left: 20px;">系统将在<span style="color:red">' + s + '</span>秒后自动保存数据,点击"取消"按钮,放弃保存操作。</h4>';
                    $(document.getElementsByName("TimeCount")).html("" + str + "");
                    s--;
                }
            }, 1000);

效果:







Book Description A hands-on approach to mastering the fundamentals of Grunt Overview Gain insight on the core concepts of Grunt, Node.js and npm to get started with Grunt. Learn how to install, configure, run, and customize Grunt Example-driven and filled with tips to help you create custom Grunt tasks In Detail In recent times, modern web browsers have become the application platform of choice. Grunt, along with its wide range of plugins, provides a simple way of managing the large number of build tasks required to maintain a sophisticated web application. Getting Started with Grunt: The JavaScript Task Runner provides you with all the information you need to become an effective Grunt power-user. You will quickly learn how to install, configure, and run Grunt. You will go on to understand how to use third-party Grunt and then create your own Grunt tasks that cater to your particular needs. This book first demonstrates various Grunt use cases before running through the steps of installing, configuring, running, and customizing Grunt. You will learn how to install Node.js, the Node.js package manager (npm), and Grunt. Then, you will understand how to set up and configure a personalized Grunt environment. Next, you will look at the various methods of running and customizing Grunt to utilize its flexibility. Finally, to emphasise what has been learnt, you will see a complete example build of a web application. Getting Started with Grunt: The JavaScript Task Runner will enable you to create your very own Grunt environments from scratch and fully utilize Grunt's large feature set to effectively solve your custom requirements. What you will learn from this book Learn about Grunt and its advantages Understand Node.js and how it relates to Grunt Take an in-depth look at npm, Node.js modules, and the working of Grunt plugins Get familiar with installing Grunt and setting up your first Grunt build environment Gain insight on the methods of configuring Grunt and when each method should be used Effectively execute Grunt through the use of task arguments, task aliasing, multi-task targets, and more Construct your own Grunt tasks, multi-tasks, and asynchronous tasks Approach A step-by-step, practical tutorial to help you transform into a Grunt power-user. Who this book is written for This book is for JavaScript developers who want to get to grips with GruntJS and use it to build and test their JavaScript applications. The only requirement for this book is a basic understanding of objects and functions in JavaScript. Product Details Paperback: 132 pages Publisher: Packt Publishing (February 19, 2014) Language: English ISBN-10: 1783980621 ISBN-13: 978-1783980628 Product Dimensions: 9.2 x 7.5 x 0.3 inches
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值