//添加事件侦听 function addListener(e, eventType, listener) { Event.observe(e, eventType, listener); }; //是否零长度字符串 function IsNone(s) { return s.toString().empty(); } //是否只有空白字符 function IsEmpty(s) { return s.toString().blank(); } //是否是数字 function IsNumber(s) { s = s.toString(); if (s.empty() || s.blank()) return false; return !isNaN(s); } //是否是整数 function IsInteger(s) { if (!IsNumber(s)) return false; s = (s - 0).toString(); return s.match(/^[-]?/d{1,15}$/gi) != null; //整型精度为15位。 } //是否是双精度型 function IsDouble(s) { if (!IsNumber(s)) return false; s = (s - 0).toString(); if (s.match(/^[-]?(/d+)[.]?(/d+)$/gi) == null) return false; return RegExp.$1.length + RegExp.$2.length <= 17; //浮点型精度为17位。 } function IsDate(s) { var reg = /^((((1[6-9]|[2-9]/d)/d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]/d|3[01]))|(((1[6-9]|[2-9]/d)/d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]/d|30))|(((1[6-9]|[2-9]/d)/d{2})-0?2-(0?[1-9]|1/d|2[0-8]))|(((1[6-9]|[2-9]/d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$/; return reg.test(s); } function IsTime(str) { var tmp = str.toString(); return (tmp.match(/^([01]?[0-9]|2[0-3]):([012345]?[0-9]|5[1-9]):([012345]?[0-9]|5[1-9])$/g) != null) } //功能:常用正则表达式 function isEmail(str) { return str.toString().match(/^(?:[;]?[/w_-]+(?:[.][/w_-]+)*@[/w_-]+(?:[.][/w_-]+)+)+$/gi) != null; } function isQQ(str) { return str.toString().match(/^[1-9]/d{4,12}$/g) != null; } //xxxx-xxxxxxxx-xxxx function isPhone(str) { return str.toString().match(/^((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?$/g) != null; } //1xxxxxxxxxx function isMobile(str) { return str.toString().match(/^((/(/d{2,3}/))|(/d{3}/-))?1/d{10}$/g) != null; } //1xxxxxxxxxxx,xxxx-xxxxxxxx-xxxx,... //"^(()|())(,(()|()))*$" function isPhoneOrMobileList(str) { return str.toString().match(/^((((/(/d{2,3}/))|(/d{3}/-))?1/d{10})|(((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?))(,((((/(/d{2,3}/))|(/d{3}/-))?1/d{10})|(((/(/d{2,3}/))|(/d{3}/-))?(/(0/d{2,3}/)|0/d{2,3}-)?[1-9]/d{6,7}(/-/d{1,4})?)))*$/g) != null; } //xx@xx.xx,xx@xx.xx,... function isEmailList(emails) { return emails.all(function(email) { return isEmail(email.strip()); }); } //A-Z,a~z,0~9,",","-" function isAscii(str) { return str.toString().match(/^[A-Za-z0-9,-]*$/gi) != null; } //http:// or https:// function isUrl(str) { return str.toString().match(/^(http|https):[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^/"/"])*$/gi) != null; } function isFtp(str) { return str.toString().match(/^ftp:[A-Za-z0-9]+/.[A-Za-z0-9]+[//=/?%/-&_~`@[/]/':+!]*([^/"/"])*$/gi) != null; } function isPostCode(str) { return str.toString().match(/^[0-9]{6}$/g) != null; } //检测有无重复邮箱名 function checkEmailsReteration(emails) { return emails.length > emails.map(function(email) { return email.strip().toLowerCase(); }).uniq().length; } //功能:页面展示时,处理文章编辑器中插入的图片的尺寸,使之适合页面大小,避免破坏页面布局 function ResizeImage(handleObj,w,h) { var coll = handleObj.select("img"); for(var i = 0; i < coll.length; i++) { var iWidth = coll[i].width; var iHeight = coll[i].height; if(coll[i].style.width != "") iWidth = parseInt(coll[i].style.width); if(coll[i].style.height != "") iHeight = parseInt(coll[i].style.height); if(iWidth >= iHeight) { if(iWidth> w) { if(coll[i].style.width != "") { coll[i].style.width = w; coll[i].style.height = (w * iHeight)/ iWidth; } else { coll[i].width = w; coll[i].height = (w * iHeight)/ iWidth; } } } else { if(iHeight > h) { if(coll[i].style.width != "") { coll[i].style.width = (h * iWidth)/ iHeight; coll[i].style.height = h; } else { coll[i].height = h; coll[i].width = (h * iWidth)/ iHeight; } } } } } function ResizeImageInWidth(handleObj,w,h) { var coll = handleObj.select("img"); var newW = 0, newH = 0; for(var i = 0; i < coll.length; i++) { var iWidth = coll[i].width; var iHeight = coll[i].height; if(coll[i].style.width != "") iWidth = parseInt(coll[i].style.width); if(coll[i].style.height != "") iHeight = parseInt(coll[i].style.height); if(iWidth >= iHeight) { if(iWidth> w) { newW = w; newH = (w * iHeight)/ iWidth; } } else { if(iWidth> w) { newW = w; newH = (w * iHeight)/ iWidth; if(newH > (1.5*h)) newH = 1.5*h; } else if(iHeight > (1.5*h)) { newW = iWidth; newH = 1.5*h; } } if(newW > 0) { if(coll[i].style.width != "") { coll[i].style.width = newW; coll[i].style.height = newH; } else { coll[i].width = newW; coll[i].height = newH; } newW = 0; newH = 0; } } } function resizeImageByWidth(o, width) { var oldWidth = 0; var oldHeight = 0; if(o != null && width > 0) { oldWidth = parseInt(o.width); oldHeight = parseInt(o.height); if(oldWidth > 0 && oldHeight > 0) { var z = width / oldWidth; var height = parseInt(oldHeight * z); o.width = width; o.height = height; } } } function resizeImageByWidthEx(srcWidth, srcHeight, setWidth){ return (srcWidth > 0 && srcHeight > 0 && srcWidth > setWidth) ? {width: setWidth, height: srcHeight * (setWidth / srcWidth)} : {width: srcWidth, height: srcHeight}; } function SetSameHeight() { var divLeft = $("divDoorLeft"); var divMiddle = $("divDoorMiddle"); var divRight = $("divDoorRight"); var divMain = $("divDoorMain"); if(divLeft!=null) { var maxHeight = 0; if(divMain != null) { maxHeight = Math.max(divLeft.scrollHeight, divMain.scrollHeight); divLeft.style.height = maxHeight-25 + 'px'; divMain.style.height = maxHeight + 'px'; } else { maxHeight = Math.max(divLeft.scrollHeight,divMiddle.scrollHeight, divRight.scrollHeight); divLeft.style.height = maxHeight-25 + 'px'; if(divMiddle.scrollHeight < maxHeight) divMiddle.style.height = maxHeight + 'px'; divRight.style.height = maxHeight-25 + 'px'; } } } function SetLate() { SetSameHeight.delay(1); } function MM_swapImgRestore() { var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { var d=document; if(d.images) { if(!d.MM_p) d.MM_p = []; var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0) { d.MM_p[j]=new Image; d.MM_p[j++].src=a[i]; } } } function MM_findObj(n, d) { var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); } if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x) x = $(n); return x; } function MM_swapImage() { var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr = []; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null) { document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2]; } } //定位到指定锚位置 function gotoAnchorLocation(id) { var url = self.location.pathname; var search = self.location.search; self.location = url + search + "#cmt" + id; } function trim(str) { // from: http://www.cnblogs.com/rubylouvre/archive/2009/09/18/1568794.html if (str.length == 0) return ""; str = str.replace(/^/s/s*/, ''), ws = //s/, i = str.length; while (ws.test(str.charAt(--i))) ; return str.slice(0, i + 1); } // http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_number_format/ function numberFormat (number, decimals, decPoint, thousandsSep) { var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 0 : decimals, d = decPoint === undefined ? "." : decPoint, t = thousandsSep === undefined ? "," : thousandsSep, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(/d{3})(?=/d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); };