LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

javascript 常用代码大全(超级收藏,强烈推荐)(3)

admin
2010年4月26日 23:18 本文热度 7688
[p]打开模式对话框 [br]返回模式对话框的值 [br]全屏幕打开 ie 窗口[br]脚本中中使用xml [br]一、验证类 [br]1、数字验证内[br]2、时间类[br]3、表单类[br]4、字符类[br]5、浏览器类[br]6、结合类[/p]
[p][align=left]二、功能类 [br]1、时间与相关控件类[br]2、表单类 [br]3、打印类 [br]4、事件类 [br]5、网页设计类[br]6、树型结构。[br]7、无边框效果的制作 [br]8、连动下拉框技术 [br]9、文本排序 [br]10,画图类,含饼、柱、矢量贝滋曲线 [br]11,操纵客户端注册表类 [br]12,div层相关(拖拽、显示、隐藏、移动、增加) [br]13,tablae相关(客户端动态增加行列,模拟进度条,滚动列表等) [br]14,各种object classid=>相关类,如播放器,flash与脚本互动等 [br]16, 刷新/模拟无刷新 异步调用类(xmlhttp或iframe,frame) [/align][/p]
[br]针对javascript的几个对象的扩充函数 [br]function checkbrowser() [br]{ [br]this.ver=navigator.appversion [br]this.dom=document.getelementbyid?1:0 [br]this.ie6=(this.ver.indexof("msie 6")>-1 && this.dom)?1:0; [br]this.ie5=(this.ver.indexof("msie 5")>-1 && this.dom)?1:0; [br]this.ie4=(document.all && !this.dom)?1:0; [br]this.ns5=(this.dom && parseint(this.ver) >= 5) ?1:0; [br]this.ns4=(document.layers && !this.dom)?1:0; [br]this.mac=(this.ver.indexof('mac') > -1) ?1:0; [br]this.ope=(navigator.useragent.indexof('opera')>-1); [br]this.ie=(this.ie6 || this.ie5 || this.ie4) [br]this.ns=(this.ns4 || this.ns5) [br]this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns5 || this.ns4 || this.mac || this.ope) [br]this.nbw=(!this.bw)
return this; [br]} [br]/* [br]****************************************** [br]日期函数扩充 [br]****************************************** [br]*/
[br]/* [br]=========================================== [br]//转换成大写日期(中文) [br]=========================================== [br]*/ [br]date.prototype.tocase = function() [br]{ [br]var digits= new array('零','一','二','三','四','五','六','七','八','九','十','十一','十二'); [br]var unit= new array('年','月','日','点','分','秒');
var year= this.getyear() + ""; [br]var index; [br]var output="";
////////得到年 [br]for (index=0;index ///////得到月 [br]output +=digits[this.getmonth()] + unit[1];
///////得到日 [br]switch (parseint(this.getdate() / 10)) [br]{ [br]case 0: [br]output +=digits[this.getdate() % 10]; [br]break; [br]case 1: [br]output +=digits[10] + ((this.getdate() % 10)>0?digits[(this.getdate() % 10)]:""); [br]break; [br]case 2: [br]case 3: [br]output +=digits[parseint(this.getdate() / 10)] + digits[10] + ((this.getdate() % 10)>0?digits[(this.getdate() % 10)]:""); [br]default:
break; [br]} [br]output +=unit[2];
///////得到时 [br]switch (parseint(this.gethours() / 10)) [br]{ [br]case 0: [br]output +=digits[this.gethours() % 10]; [br]break; [br]case 1: [br]output +=digits[10] + ((this.gethours() % 10)>0?digits[(this.gethours() % 10)]:""); [br]break; [br]case 2: [br]output +=digits[parseint(this.gethours() / 10)] + digits[10] + ((this.gethours() % 10)>0?digits[(this.gethours() % 10)]:""); [br]break; [br]} [br]output +=unit[3];
if(this.getminutes()==0&&this.getseconds()==0) [br]{ [br]output +="整"; [br]return output; [br]}
///////得到分 [br]switch (parseint(this.getminutes() / 10)) [br]{ [br]case 0: [br]output +=digits[this.getminutes() % 10]; [br]break; [br]case 1: [br]output +=digits[10] + ((this.getminutes() % 10)>0?digits[(this.getminutes() % 10)]:""); [br]break; [br]case 2: [br]case 3: [br]case 4: [br]case 5: [br]output +=digits[parseint(this.getminutes() / 10)] + digits[10] + ((this.getminutes() % 10)>0?digits[(this.getminutes() % 10)]:""); [br]break; [br]} [br]output +=unit[4];
if(this.getseconds()==0) [br]{ [br]output +="整"; [br]return output; [br]}
///////得到秒 [br]switch (parseint(this.getseconds() / 10)) [br]{ [br]case 0: [br]output +=digits[this.getseconds() % 10]; [br]break; [br]case 1: [br]output +=digits[10] + ((this.getseconds() % 10)>0?digits[(this.getseconds() % 10)]:""); [br]break; [br]case 2: [br]case 3: [br]case 4: [br]case 5: [br]output +=digits[parseint(this.getseconds() / 10)] + digits[10] + ((this.getseconds() % 10)>0?digits[(this.getseconds() % 10)]:""); [br]break; [br]} [br]output +=unit[5];

return output; [br]}
[br]/* [br]=========================================== [br]//转换成农历 [br]=========================================== [br]*/ [br]date.prototype.tochinese = function() [br]{ [br]//暂缺 [br]}
/* [br]=========================================== [br]//是否是闰年 [br]=========================================== [br]*/ [br]date.prototype.isleapyear = function() [br]{ [br]return (0==this.getyear()%4&&((this.getyear()%100!=0)||(this.getyear()%400==0))); [br]}
/* [br]=========================================== [br]//获得该月的天数 [br]=========================================== [br]*/ [br]date.prototype.getdaycountinmonth = function() [br]{ [br]var mon = new array(12);
mon[0] = 31; mon[1] = 28; mon[2] = 31; mon[3] = 30; mon[4] = 31; mon[5] = 30; [br] mon[6] = 31; mon[7] = 31; mon[8] = 30; mon[9] = 31; mon[10] = 30; mon[11] = 31;
if(0==this.getyear()%4&&((this.getyear()%100!=0)||(this.getyear()%400==0))&&this.getmonth()==2) [br]{ [br]return 29; [br]} [br]else [br]{ [br]return mon[this.getmonth()]; [br]} [br]}
[br]/* [br]=========================================== [br]//日期比较 [br]=========================================== [br]*/ [br]date.prototype.compare = function(objdate) [br]{ [br]if(typeof(objdate)!="object" && objdate.constructor != date) [br]{ [br]return -2; [br]}
var d = this.gettime() - objdate.gettime();
if(d>0) [br]{ [br]return 1; [br]} [br]else if(d==0) [br]{ [br]return 0; [br]} [br]else [br]{ [br]return -1; [br]} [br]}
/* [br]=========================================== [br]//格式化日期格式 [br]=========================================== [br]*/ [br]date.prototype.format = function(formatstr) [br]{ [br]var str = formatstr;
str=str.replace(/yyyy|yyyy/,this.getfullyear()); [br]str=str.replace(/yy|yy/,(this.getyear() % 100)>9?(this.getyear() % 100).tostring():"0" + (this.getyear() % 100));
str=str.replace(/mm/,this.getmonth()>9?this.getmonth().tostring():"0" + this.getmonth()); [br]str=str.replace(/m/g,this.getmonth());
str=str.replace(/dd|dd/,this.getdate()>9?this.getdate().tostring():"0" + this.getdate()); [br]str=str.replace(/d|d/g,this.getdate());
str=str.replace(/hh|hh/,this.gethours()>9?this.gethours().tostring():"0" + this.gethours()); [br]str=str.replace(/h|h/g,this.gethours());
str=str.replace(/mm/,this.getminutes()>9?this.getminutes().tostring():"0" + this.getminutes()); [br]str=str.replace(/m/g,this.getminutes());
str=str.replace(/ss|ss/,this.getseconds()>9?this.getseconds().tostring():"0" + this.getseconds()); [br]str=str.replace(/s|s/g,this.getseconds());
return str; [br]}
[br]/* [br]=========================================== [br]//由字符串直接实例日期对象 [br]=========================================== [br]*/ [br]date.prototype.instancefromstring = function(str) [br]{ [br]return new date("2004-10-10".replace(/-/g, "\/")); [br]}
/* [br]=========================================== [br]//得到日期年月日等加数字后的日期 [br]=========================================== [br]*/ [br]date.prototype.dateadd = function(interval,number) [br]{ [br]var date = this;
switch(interval) [br] { [br] case "y" : [br] date.setfullyear(date.getfullyear()+number); [br] return date;
case "q" : [br] date.setmonth(date.getmonth()+number*3); [br] return date;
case "m" : [br] date.setmonth(date.getmonth()+number); [br] return date;
case "w" : [br] date.setdate(date.getdate()+number*7); [br] return date; [br] [br] case "d" : [br] date.setdate(date.getdate()+number); [br] return date;
case "h" : [br] date.sethours(date.gethours()+number); [br] return date;
case "m" : [br] date.setminutes(date.getminutes()+number); [br] return date;
case "s" : [br] date.setseconds(date.getseconds()+number); [br] return date;
default : [br] date.setdate(d.getdate()+number); [br] return date; [br] } [br]}
/* [br]=========================================== [br]//计算两日期相差的日期年月日等 [br]=========================================== [br]*/ [br]date.prototype.datediff = function(interval,objdate) [br]{ [br]//暂缺 [br]}
[br]/* [br]****************************************** [br]数字函数扩充 [br]****************************************** [br]*/
/* [br]=========================================== [br]//转换成中文大写数字 [br]=========================================== [br]*/ [br]number.prototype.tochinese = function() [br]{ [br]var num = this; [br] if(!/^\d*(\.\d*)?$/.test(num)){alert("number is wrong!"); return "number is wrong!";}
var aa = new array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"); [br] var bb = new array("","拾","佰","仟","萬","億","点",""); [br] [br] var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
for(var i=a[0].length-1; i>=0; i--) [br] { [br] switch(k) [br] { [br] case 0 : re = bb[7] + re; break; [br] case 4 : if(!new regexp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0])) [br] re = bb[4] + re; break; [br] case 8 : re = bb[5] + re; bb[7] = bb[5]; k = 0; break; [br] } [br] if(k%4 == 2 && a[0].charat(i+2) != 0 && a[0].charat(i+1) == 0) re = aa[0] + re; [br] if(a[0].charat(i) != 0) re = aa[a[0].charat(i)] + bb[k%4] + re; k++; [br] }
if(a.length>1) //加上小数部分(如果有小数部分) [br] { [br] re += bb[6]; [br] for(var i=0; i }
/* [br]=========================================== [br]//保留小数点位数 [br]=========================================== [br]*/ [br]number.prototype.tofixed=function(len) [br]{
if(isnan(len)||len==null) [br]{ [br]len = 0; [br]} [br]else [br]{ [br]if(len<0) [br]{ [br]len = 0; [br]} [br]}
return math.round(this * math.pow(10,len)) / math.pow(10,len);
}
/* [br]=========================================== [br]//转换成大写金额 [br]=========================================== [br]*/ [br]number.prototype.tomoney = function() [br]{ [br]// constants: [br]var maximum_number = 99999999999.99; [br]// predefine the radix characters and currency symbols for output: [br]var cn_zero= "零"; [br]var cn_one= "壹"; [br]var cn_two= "贰"; [br]var cn_three= "叁"; [br]var cn_four= "肆"; [br]var cn_five= "伍"; [br]var cn_six= "陆"; [br]var cn_seven= "柒"; [br]var cn_eight= "捌"; [br]var cn_nine= "玖"; [br]var cn_ten= "拾"; [br]var cn_hundred= "佰"; [br]var cn_thousand = "仟"; [br]var cn_ten_thousand= "万"; [br]var cn_hundred_million= "亿"; [br]var cn_symbol= ""; [br]var cn_dollar= "元"; [br]var cn_ten_cent = "角"; [br]var cn_cent= "分"; [br]var cn_integer= "整"; [br] [br]// variables: [br]var integral; // represent integral part of digit number. [br]var decimal; // represent decimal part of digit number. [br]var outputcharacters; // the output result. [br]var parts; [br]var digits, radices, bigradices, decimals; [br]var zerocount; [br]var i, p, d; [br]var quotient, modulus; [br] [br]if (this > maximum_number) [br]{ [br]return ""; [br]} [br] [br]// process the coversion from currency digits to characters: [br]// separate integral and decimal parts before processing coversion:
parts = (this + "").split("."); [br]if (parts.length > 1) [br]{ [br]integral = parts[0]; [br]decimal = parts[1]; [br]// cut down redundant decimal digits that are after the second. [br]decimal = decimal.substr(0, 2); [br]} [br]else [br]{ [br]integral = parts[0]; [br]decimal = ""; [br]} [br]// prepare the characters corresponding to the digits: [br]digits= new array(cn_zero, cn_one, cn_two, cn_three, cn_four, cn_five, cn_six, cn_seven, cn_eight, cn_nine); [br]radices= new array("", cn_ten, cn_hundred, cn_thousand); [br]bigradices= new array("", cn_ten_thousand, cn_hundred_million); [br]decimals= new array(cn_ten_cent, cn_cent);
// start processing: [br] outputcharacters = ""; [br]// process integral part if it is larger than 0: [br]if (number(integral) > 0) [br]{ [br]zerocount = 0; [br]for (i = 0; i < integral.length; i++) [br]{ [br]p = integral.length - i - 1; [br]d = integral.substr(i, 1); [br]quotient = p / 4; [br]modulus = p % 4; [br]if (d == "0") [br]{ [br]zerocount++; [br]} [br]else [br]{ [br]if (zerocount > 0) [br]{ [br]outputcharacters += digits[0]; [br]} [br]zerocount = 0; [br]outputcharacters += digits[number(d)] + radices[modulus]; [br]}
if (modulus == 0 && zerocount < 4) [br]{ [br]outputcharacters += bigradices[quotient]; [br]} [br]}
outputcharacters += cn_dollar; [br]}
// process decimal part if there is: [br]if (decimal != "") [br]{ [br]for (i = 0; i < decimal.length; i++) [br]{ [br]d = decimal.substr(i, 1); [br]if (d != "0") [br]{ [br]outputcharacters += digits[number(d)] + decimals[i]; [br]} [br]} [br]}
// confirm and return the final output string: [br]if (outputcharacters == "") [br]{ [br]outputcharacters = cn_zero + cn_dollar; [br]} [br]if (decimal == "") [br]{ [br]outputcharacters += cn_integer; [br]}
outputcharacters = cn_symbol + outputcharacters; [br]return outputcharacters; [br]}
[br]number.prototype.toimage = function() [br]{ [br]var num = array( [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0x5,0x5,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0x4,0x4,0x4,0x4,0x4}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0xf,0x1,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0xf,0x4,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0x5,0x5,0xf,0x4,0x4}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x1,0xf,0x4,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x1,0xf,0x5,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x4,0x4,0x4,0x4}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0xf,0x5,0xf}", [br]"#define t_width 3\n#define t_height 5\nstatic char t_bits[] = {0xf,0x5,0xf,0x4,0xf}" [br]);
var str = this + ""; [br]var iindex [br]var result="" [br]for(iindex=0;iindex [br]}
return result; [br]}
[br]/* [br]****************************************** [br]其他函数扩充 [br]****************************************** [br]*/
[br]/* [br]=========================================== [br]//验证类函数 [br]=========================================== [br]*/ [br]function isempty(obj) [br]{
obj=document.getelementsbyname(obj).item(0); [br] if(trim(obj.value)=="") [br] { [br] [br] if(obj.disabled==false && obj.readonly==false) [br] { [br] obj.focus(); [br] } [br]return true; [br] } [br]else [br]{ [br]return false; [br]} [br]}
/* [br]=========================================== [br]//无模式提示对话框 [br]=========================================== [br]*/ [br]function modelessalert(msg) [br]{ [br] window.showmodelessdialog("javascript:alert(\""+escape(msg)+"\");window.close();","","status:no;resizable:no;h

该文章在 2010/4/26 23:18:39 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved