1、l 去字符前后空格 String.prototype.trim = function() { return this.replace(/(^\s+)|\s+$/g,""); } l 自动关闭弹出窗口 function autoCloseAlert(msg,timeLong) { try { if(timeLong==null) timeLong=1000; var tempFrm=document.getElementById("msgFrm"); if(tempFrm==null||typeof(tempFrm)=="undefined")
2、 { tempFrm =document.createElement("iframe"); document.body.appendChild(tempFrm); tempFrm.id = "msgFrm"; tempFrm.name ="msgFrm"; tempFrm.style.display="none"; } msg=msg.replace(/"/g,"\\\""); msg=msg.replace(/\n/g,"\\n"); var sfeature="status:no;resizable:no;help:no;
3、dialogHeight:height:30px;dialogHeight:40px;"; msgFrm.showModelessDialog("javascript:alert(\""+msg+"\");window.close();","",sfeature); setTimeout("msgFrm.location.reload();",timeLong); }catch(e) { alert(msg); } } l 指定打印机打印 try { var nt = new ActiveXObject("WScript.Networ
4、k"); nt.SetDefaultPrinter(commonPrinter);//commonPrinter 打印名 }catch(e){} l 读取本地文件 try { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fileFullPath=”c:\readme.txt”;//文件路径 if(!fso.FileExists(fileFullPath)) { alert(‘没有找到此文件’); }else { var fil
5、e=fso.OpenTextFile(fileFullPath,ForReading); var inFileInfo=file.ReadLine(); } }catch(e){} l 判断文件是否存在 function fileIsExist(filePath) { try { var obj=new ActiveXObject("MSXML2.XMLHTTP"); obj.open("Get",filePath,false); obj.send(); if(obj.status==404){ return
6、 false; }else { return true; } }catch(e){ //alert(e.description+":"+filePath); return false; } } l JS文件操作 //如果文件存在,则先删除这临时文件夹 try { //得到图片目录地址 var fso=new ActiveXObject("Scripting.FileSystemObject"); contentPath=fso.GetParentFolderName(tempImg); //如果是第一次加载,则删除临
7、时数据 if(loadImgCount==0) { //先删除临时数据 fso.DeleteFolder(contentPath); } //生成新的二维码图片 tempImg=MakeBarCode.getPdf417(printData); if(fso.FileExists(tempImg)) { //得到当前文件 var file=fso.getFile(tempImg); //新图片URL var tempFileName=(new Date()).getTime();//文件名称 newImgSrc=co
8、ntentPath+"\\"+tempFileName+".bmp"; //alert("新图片URL:"+newImgSrc); //重命名二维码图片 file.Move(newImgSrc); //显示图片 barcode.style.display=""; barcode_img.src=newImgSrc; } }catch(e) { alert('打印失败:你禁用了ActiveX控件,加载图片失败或'+e.decription); isOk=true; window.close(); return; } l 退出窗体前提
9、示 function window.onbeforeunload() { alert(‘是否退出’); } l 窗体边界设置
l 指定边界打印 l DIV文字居中17、d="contentTb">
| 第一页打印 |
18、e width="98%" border="0" cellspacing="0" cellpadding="2" align="center" style="">
| 格 数 | 收件机关名称及收件人 | 号 码 | 发 件 单 位 | 种 类 | 件 数 | 备 考 | |
| 绝密 | 机密 24、td> | ||||||
25、me1,objName2) { var objValue1=document.all.item(objName1).value; var objValue2=document.all.item(objName2).value; if(objValue1==null||objValue1.length==0) { document.all.item(objName1).value=objValue2; }else { var OneMonth = objValue1.substring(5,objValue1.lastIndexOf ("-"));
26、 var OneDay = objValue1.substring(objValue1.length,objValue1.lastIndexOf ("-")+1); var OneYear = objValue1.substring(0,objValue1.indexOf ("-")); var TwoMonth = objValue2.substring(5,objValue2.lastIndexOf ("-")); var TwoDay = objValue2.substring(objValue2.length,objValue2.lastIndexOf ("-")
27、1); var TwoYear = objValue2.substring(0,objValue2.indexOf ("-")); if(Date.parse(OneMonth+"/"+OneDay+"/"+OneYear)>Date.parse(TwoMonth+"/"+TwoDay+"/"+TwoYear)) { alert('后者日期小于前都日期'); document.all.item(objName2).value=""; } } } //日期比较 function compareDate(beginDate,
28、endDate) { var date11=new Date(beginDate.replace("-",",")).getTime(); var date22=new Date(endDate.replace("-",",")).getTime(); //结束日期是否大于开始日期 return (date22>=date11) } l JS 函数 EVAL(Str) EVAL() 执行一段js脚本, 如 eval(3+5)=8 l 列出所有打印机 var nt = new ActiveXObject("WScript.Networ
29、k"); var oPrinters = nt.EnumPrinterConnections(); if(oPrinters==null||oPrinters.length==0) { alert('当前你的机器暂没安装打印机'); return; }else { //alert('当前打印机台数:'+oPrinters.length); } l 清空页码 function changePageSet() { var HKEY_Root,HKEY_Path,HKEY_Key; HKEY_Root="HKEY_CURRENT_US
30、ER"; HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; HKEY_HEADER_Key="header"; HKEY_ROOTER_Key="footer"; try { var Wsh=new ActiveXObject("WScript.Shell"); //设置页码 var pageSet=document.getElementsByName("pageSet"); if(pageSet==null) return; f
31、or(i=0;i 32、KEY_Root+HKEY_Path+HKEY_HEADER_Key,"&u&b&d");
}
}
}catch(e)
{
alert('设置页码失败:可能原因你禁止了ActiveX控件');
return;
}
}
l 替换函数
function ReplaceAll(strOrg,strFind,strReplace){
var index = 0;
while(strOrg.indexOf(strFind,index) != -1){
strOrg = strOrg.replace(strFind 33、strReplace);
index = strOrg.indexOf(strFind,index);
}
return strOrg
}
l 限制输入,只能输入数字
34、value))execCommand('undo')">
l JS实现“取消”与“还原”
实现JS UndoAndRedo.jsvar actionStack = [];//操作栈
var actionIndex = 0;//操作栈中当前操作的指针
//----------------------- command对象基类 ------------------------------
function BaseAction(){
}
BaseAction.prototype.exec=function(){
actionStack[actionInd 35、ex++] = this;
actionStack.length = actionIndex;
}
BaseAction.prototype.undo=function(){
alert("此操作未定义相应的undo操作");
}
BaseAction.prototype.redo=function(){
alert("此操作未定义相应的redo操作");
}
function ChangeAction(elm){
this.sourceElement = elm;
this.oldValue = elm.d 36、efaultValue;
this.newValue = elm.value;
elm.defaultValue = elm.value;
this.status = "done";
}
ChangeAction.prototype = new BaseAction();
ChangeAction.prototype.undo = function(){
if (this.status != "done") return;
this.sourceElement.value = this.sourceElement.defaultValue 37、 = this.oldValue;
this.status = "undone";
}
ChangeAction.prototype.redo = function(){
if (this.status != "undone") return;
this.sourceElement.value = this.newValue;
this.status = "done";
}
//--------------------- 全局函数 ----------------------------
function undo(){
38、 if (actionIndex>0){
actionStack[--actionIndex].undo();
}
}
function redo(){
if (actionIndex 40、ck='undo();' style="cursor:hand">
41、
if (datestr != "")
lthdatestr= datestr.length ;
else
lthdatestr=0;
var tmpy="";
var tmpm="";
var tmpd="";
var status;
status=0;
if ( lthdatestr== 0) return false;
for (i=0;i 42、us>2)
{
//alert("Invalid format of date!");
return false;
}
if ((status==0) && (datestr.charAt(i)!='-'))
{
tmpy=tmpy+datestr.charAt(i)
}
if ((status==1) && (datestr.charAt(i)!='-'))
{
tmpm=tmpm+datestr.charAt(i)
}
if ((status==2) && (datestr.ch 43、arAt(i)!='-'))
{
tmpd=tmpd+datestr.charAt(i)
}
}
year=new String (tmpy);
month=new String (tmpm);
day=new String (tmpd)
//tempdate= new String (year+month+day);
//alert(tempdate);
if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
{
//alert("Invali 44、d format of date!");
return false;
}
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
{
//alert ("Invalid month or day!");
return false;
}
if (!((year % 4)==0) && (month==2) && (day==29))
{
//alert ("This is not a leap year!");
return false;
}
i 45、f ((month<=7) && ((month % 2)==0) && (day>=31))
{
//alert ("This month is a small month!");
return false;
}
if ((month>=8) && ((month % 2)==1) && (day>=31))
{
//alert ("This month is a small month!");
return false;
}
if ((month==2) && (day==30))
{
//alert("Th 46、e Febryary never has this day!");
return false;
}
return true;
}
l 检查Email格式
//是否邮编格式
function CheckPost(Str)
{
var validChar = "0123456789";
var i;
if ( Str.length < 6 ) return false;
for (i=0;i 47、r.charAt(i) ) == -1) return false;
}
return true;
}
l 检查是否纯数字
//是否是纯数字
function CheckNum(Str)
{
var validChar = "-0123456789";
var i;
for (i = 0; i < Str.length; i++)
{
var c = Str.charAt(i);
if (validChar.indexOf(c) == -1) return false;
}
return true;
}
l 检查纯中文
//是否纯中 48、文
function CheckHZ(param)
{
var reg = /[^u4E00-u9FA5]/g;
if(reg.test(param)) return false;
return true;
}
l 去掉字符所有的字符
//去掉字符串内所有多余空格
function Alltrim(str)
{
while (str.charAt(0)==" "||str.charAt(0)==" ")
{
str=str.substr(1);
}
while (str.charAt(str.length-1 49、)==" "||str.charAt(0)==" ")
{
str=str.substr(0,str.length-1);
}
return(str);
}
附录资料:
Ehcache缓存配置
简介
Cache的配置很灵活,官方提供的Cache配置方式有好几种。你可以通过声明配置、在xml中配置、在程序里配置或者调用构造方法时传入不同的参数。
你可以将Cache的配置从代码中剥离出来,也可以在使用运行时配置,所谓的运行时配置无非也就是在代码中配置。以下是运行时配置的好处:
· 在同一个地方配置所有的Cache,这样很容易管理Ca 50、che的内存和磁盘消耗。
· 发布时可更改Cache配置。
· 可再安装阶段就检查出配置错误信息,而避免了运行时错误。
本文将会对ehcache.xml配置文件进行详细的阐述。在配置的时可以拷贝一个现有的ehcache.xml,如果没有请点击这里去下载。
ehcache-failsafe.xml
如果你调用了CacheManager默认构造方法去创建CacheManager的实例,此方法会到classpath中找ehcache.xml文件,否则它会到类路径下找ehcache-failsafe.xml文件。而ehcache-failsafe.xml被包含在jar包
l 检查日期是否合法
//函数名:chkdate
//功能介绍:检查是否为日期
//参数说明:要检查的字符串
//返回值:0:不是日期 1:是日期
function CheckDate(datestr)
{
var lthdatestr






