//author: neeler_nitmoon note: 常用方法库 (function($) { $.getUrlParam = function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; } })(jQuery); /*********showErrmsg START**********************/ /** *showErrmsg */ //错误提示 function showErrmsg(str, callback) { var neelerErrmsg = $("#neelerErrmsg"); if (!neelerErrmsg.length) { setErrmsg(); neelerErrmsg = $("#neelerErrmsg"); } if (!!window.neelerFlag) { return; } // window.neelerFlag = 1; neelerErrmsg.text(str).fadeIn("slow", function() { window.neelerFlag = true; setTimeout(function() { neelerErrmsg.fadeOut("slow", function() { if (callback != undefined && callback != "") { callback(); } }); window.neelerFlag = false; }, 3000); }); } function setErrmsg() { var neelerErrmsg = $("
") .attr("id", "neelerErrmsg") .css({ "display": "none", "position": "fixed", "top": "150px", "left": "20%", "width": "60%", "height": "50px", "border": "1px solid #000", "border-radius": "10px", "line-height": "50px", "text-align": "center", "background": "#000", "opacity": "0.6", "filter": "alpha(opacity=60)", "color": "#FFF", "z-index": "999999" }); $("body").prepend(neelerErrmsg); } /*********showErrmsg END**********************/ String.prototype.lengthLimit = function(length) { if (!length) { return; } return this.length > length ? this.substr(0, length) + '...' : this; } /*********isList START********************/ //是否为data.list数组且不为空 function isList(arr) { return ($.isArray(arr) && arr.length > 0) ? true : false; } /*********isList END**********************/ /*********ArrayUnique START**********************/ //数组去重 Array.prototype.unique = function() { var n = {}; var r = []; for (var i = 0; i < this.length; i++) { if (!n[this[i]+'']) { n[this[i]+''] = true; r.push(this[i]); } } return r; } /*********isItems START**********************/ function virtualFormSubmit(url, obj, method, target) { var form = $('').attr({ 'action': url, 'method': !!method ? method : 'post', 'target': !!target ? target : '_self' }); for (var attr in obj) { var input = $('').val(obj[attr]); form.append(input); } form.appendTo('body'); form[0].submit(); form.remove(); } /*********ntypeahead start**********************/ function ntypeahead(url, selector, callback, attr) { var obj = null; if (typeof(selector) == 'string') obj = $(selector); else obj = selector; obj.typeahead({ autoSelect: false, source: function(query, process) { window.ta_Process = []; //=== window.states=[]; window.ta_Updater = {}; //===window.map={} $.ajax({ url: url, type: 'post', data: { query: query }, dataType: 'json', ansyc: false, success: function(json) { if (json.length == 0) return; $.each(json, function(i, item) { if (item.data != undefined) { window.ta_Updater[item.name] = item.data; } window.ta_Process.push(item.name); }); process(ta_Process); } }); }, updater: function(item) { return item; // var res = {}; // if ($.isEmptyObject(window.ta_Updater)) { // if (callback != null) { // callback(item, obj); // } // return item; // } else { // res = window.ta_Updater[item]; // } // if (callback != null) { // callback(res, obj); // } // if ($.isArray(attr)) { // var r = ""; // $.each(attr, function(index, val) { // if (index == (attr.length - 1)) { // r = r + res[attr[index]]; // } else { // r = r + res[attr[index]] + "--"; // } // }); // return r; // } else { // console.log(res[attr]); // return res[attr]; // } } }); } /*********ntypeahead start**********************/ function isFunction(fn) { return (!!fn&&!fn.nodename&&fn.constructor!=String&&fn.constructor!=RegExp&&fn.constructor!=Array&&/function/i.test(fn+"")); } // 对Date的扩展,将 Date 转化为指定格式的String // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.Format = function(fmt) { //author: meizz var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("("+ k +")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); return fmt; }