JS任务开发脚本 v0.03 (20100710)
需要jquery支持 用到的版本是jquery-1.4.2.js
更新日志:
0.01 建立了基本任务模型
0.02 改进了任务管理,扩展任务属性,优化多任务处理
0.03 支持动态修改任务,添加任务执行命令
说明:适用于各种定时任务应用,请注重劳动成果!保留说明文字,以便获得技术支持。
作者:康乐
发布:www.javacs.cn中国java工作者脚本开放,兼容FF/IE,难免有不足之处,希望在大家的帮助下改进和完善它。
欢迎参与此兴趣小组!你可以到 中国java工作者家园 【群组】找到【javascript兴趣小组】欢迎加入:
http://www.javacs.cn/home/space-mtag-tagid-3.html
一个很小的功能但非常实用,在B/S开发过程中会经常用上。
附件中包含:
naozhong.html (测试用)这个界面很粗糙 
jquery-1.4.2.js 
Multi-task.js
这里不能上传,压缩包已经上传到这里http://www.javacs.cn/bbs/thread-300-1-1.html
运行效果:以下是源代码
/*!
任务开发脚本 v0.03 (20100710)
更新日志:
0.01 建立了基本任务模型
0.02 改进了任务管理,扩展任务属性,优化多任务处理
0.03 支持动态修改任务,添加任务执行命令
说明:适用于各种定时任务应用,请注重劳动成果!保留说明文字,以便获得技术支持。
作者:康乐
发布:www.javacs.cn 中国java工作者
*/
var AlarmTimeSet=new Date();
var Atimes =new Array(); 
//任务数据类
function kllz(a,b,c,d,e,f,g){ 
this.Aid=a;//编号
this.Atime=b;//时间
this.Atext=c;//提示内容
this.Amusic=d;//音乐
this.Aphoto=e;//图像
this.Ais=f;//是否提示
this.Acmd=g;//执行命令
}//生成GUID
kllz.newGuid=function(){ 
    var guid = ""; 
&nbsp; &nbsp; for (var i = 1; i <= 32; i++){ 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var n = Math.floor(Math.random()*16.0).toString(16); 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;guid += n; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if((i==8)||(i==12)||(i==16)||(i==20)) 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;guid += ""; 
&nbsp; &nbsp; } 
&nbsp; &nbsp; return guid; 
} //按index删除元素
Array.prototype.remove=function(dx)
&nbsp;&nbsp;{
&nbsp; &nbsp; if(isNaN(dx)||dx>this.length){return false;}
&nbsp; &nbsp; for(var i=0,n=0;i<this.length;i++)
&nbsp; &nbsp; {
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(this[i]!=this[dx])
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this[n++]=this[i]
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
&nbsp; &nbsp; }
&nbsp; &nbsp; this.length-=1
&nbsp;&nbsp;}
//添加任务
kllz.addAtime =function()
{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//if(Atimes.length!=0)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//Atimes+={false};
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var AlarmTime=new Date(AlarmTimeSet.getFullYear(),AlarmTimeSet.getMonth()+1,AlarmTimeSet.getDate(),$("#H").val(),$("#M").val(),$("#S").val());
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var Aist=($('#Ais').attr('checked')) ? true : false;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var lz&nbsp;&nbsp;= new kllz(kllz.newGuid(),AlarmTime,$("#SMS").val(),$("#MUSIC").val(),$("#PHOTO").val(),Aist); 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;lz.Acmd=function(){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; kllz.gxAtimes();
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; };
&nbsp; &nbsp; Atimes.push(lz);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$('#Ais').removeAttr("checked");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var i=Atimes.length;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var n=lz.Atime;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$('#t').prepend("<li id=\"time_"+lz.Aid+"\">第" + i + "个任务: " +n.getFullYear()+"-"+n.getMonth()+"-"+n.getDate()+"&nbsp;&nbsp;"+ n.getHours()+"-"+n.getMinutes()+"-"+n.getSeconds() +"\t提示内容:"+lz.Atext+"\t提示音乐:"+lz.Amusic+"\t提示图片:"+lz.Aphoto+"\t是否提示:"+lz.Ais+"<button onClick=\"kllz.delAtimeAid('"+lz.Aid+"')\">删除</button><button onClick=\"kllz.updAtimeAid('"+lz.Aid+"')\">修改</button>");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//gxAtimes();
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;AlarmClock();
}
//根据index删除任务元素
kllz.delAtime=function (i)
{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(Atimes.length>0)
&nbsp; &nbsp; Atimes.remove(i);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$('#time_'+i).remove();
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//gxAtimes();
}
//修改指定任务
kllz.updAtimeAid=function(Aid)
{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var AlarmTime=new Date(AlarmTimeSet.getFullYear(),AlarmTimeSet.getMonth()+1,AlarmTimeSet.getDate(),$("#H").val(),$("#M").val(),$("#S").val());
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var Aist=($('#Ais').attr('checked')) ? true : false;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var lz&nbsp;&nbsp;= new kllz(Aid,AlarmTime,$("#SMS").val(),$("#MUSIC").val(),$("#PHOTO").val(),Aist); 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//var ts =kllz.selAtimeAid(Aid);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//$.each(Atimes,ts,true);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(Atimes.length>0)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $.each( Atimes, function(j, m){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; var i=Atimes.length;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var n=lz.Atime;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(m.Aid==Aid)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Atimes[j]=lz;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $('#time_'+lz.Aid).html("第" + i + "个任务: " +n.getFullYear()+"-"+n.getMonth()+"-"+n.getDate()+"&nbsp;&nbsp;"+ n.getHours()+"-"+n.getMinutes()+"-"+n.getSeconds() +"\t提示内容:"+lz.Atext+"\t提示音乐:"+lz.Amusic+"\t提示图片:"+lz.Aphoto+"\t是否提示:"+lz.Ais+"<button onClick=\"kllz.delAtimeAid('"+lz.Aid+"')\">删除</button><button onClick=\"kllz.updAtimeAid('"+lz.Aid+"')\">修改</button>");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(j>=Atimes.length-1)return null;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; });
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
}
//根据Aid返回 任务元素
 kllz.selAtimeAid=function (idt)
 {
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$('#time_'+idt).remove();
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(Atimes.length>0)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $.each( Atimes, function(j, m){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(m.Aid==idt)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return Atimes[j];
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(j>=Atimes.length-1)return null;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; });
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
 }
//根据Aid删除任务元素
kllz.delAtimeAid=function (idt)
{
$('#time_'+idt).remove();
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(Atimes.length>0)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; $.each( Atimes, function(j, m){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(m.Aid==idt)
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; {
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Atimes.remove(j);
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if(j>=Atimes.length-1)return;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; });
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//gxAtimes();
}
//更新任务
kllz.gxAtimes=function ()
{
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$('#t').html("");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$.each( Atimes, function(i, m){
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;var n = m.Atime;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;$('#t').prepend("<li id=\"time_"+m.Aid+"\">第" + (i+1) + "个任务: " +n.getFullYear()+"-"+n.getMonth()+"-"+n.getDate()+"&nbsp;&nbsp;"+ n.getHours()+"-"+n.getMinutes()+"-"+n.getSeconds() +"<button onClick=\"kllz.delAtimeAid('"+m.Aid+"')\">删除</button></li>");
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if(i==Atimes.length-1)return;
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});
}
//开启任务
AlarmClock=function ()
{&nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;var TimeNowSet=new Date();
 $.each( Atimes, function(i, m){
&nbsp;&nbsp;
 n=m.Atime;
&nbsp;&nbsp;//$('#w').prepend("Item #" + i + ": " + n +"");
&nbsp;&nbsp;//任务时间
&nbsp;&nbsp;//var AlarmTime=new Date(AlarmTimeSet.getFullYear(),AlarmTimeSet.getMonth()+1,AlarmTimeSet.getDate(),H.value,M.value,S.value);
&nbsp;&nbsp;var AlarmTime=n;
&nbsp;&nbsp;//当前时间
&nbsp;&nbsp;var TimeNow=new Date(TimeNowSet.getFullYear(),TimeNowSet.getMonth()+1,TimeNowSet.getDate(),TimeNowSet.getHours(),TimeNowSet.getMinutes(),TimeNowSet.getSec....帖子内容大小限制,发不完,需要的朋友去下载看吧。