/* press enter plugin * using: $("#loginName").onEnter(function(){}) * */ (function($) { $.fn.onEnter = function(func) { this.bind('keypress', function(e) { if (e.keyCode == 13) func.apply(this, [e]); }); return this; }; })(jQuery); function QueryString(fieldName) { var urlString = document.location.search; if (urlString != null) { var typeQu = fieldName + "="; var urlEnd = urlString.indexOf(typeQu); if (urlEnd != -1) { var paramsUrl = urlString.substring(urlEnd + typeQu.length); var isEnd = paramsUrl.indexOf('&'); if (isEnd != -1) { return paramsUrl.substring(0, isEnd); } else { return paramsUrl; } } else { return null; } } else { return null; } } /* cookie */ function getCookie(theName) { if (document.cookie.length>0) { var c_list = document.cookie.split("\;"); for ( i in c_list ) { var cook = c_list[i].split("="); if ( cook[0] == theName ) { return unescape(cook[1]); } } } return null; } function setCookie(theName,value,expiredays) { var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie=theName+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString); } function timestamp() { //var str = "?sessid=" + getCookie("sessid") +"&time="+new Date().getTime(); //return "?%0C"+new Date().getTime(); return "?sessid=" + getCookie("sessid") +"&time="+new Date().getTime(); } /** * 获取图片尺寸 * cfg {img:new Image,oncomplete:new * Function, maxWidth:Number} */ var getImageSize = function(cfg) { /* 如果图片在缓存中或者图片已经指定了宽和高并且小于最大宽度 */ if (cfg.img.complete || cfg.img.width && cfg.img.height && cfg.img.width < cfg.maxWidth) { cfg.oncomplete.call({ "img" : cfg.img, "width" : cfg.img.width, "height" : cfg.img.height }, null); return; } var img = document.createElement('img'), callback = cfg.oncomplete; img.src = cfg.img.src; img.style.position='absolute'; img.style.visibility='hidden'; img.style.left='-9999px'; img.style.top='-9999px'; document.body.appendChild(img); img.onload = img.onerror = img.onreadystatechange = function() { if (img && img.readyState && img.readyState != 'loaded' && img.readyState != 'complete') { return false; } img.onload = img.onreadystatechange = img.onerror = null; callback.call({ "img" : cfg.img, "width" : img.width, "height" : img.height }, null); document.body.removeChild(img); img = null; }; }; function escapeRegExp(string) { return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); } function replaceAll(string, find, replace) { return string.replace(new RegExp(escapeRegExp(find), 'g'), replace); } function addLeadingZero(s) { return (s<10)?('0'+s):s; };