188 lines
5.6 KiB
JavaScript
188 lines
5.6 KiB
JavaScript
$(function () {
|
|
try {
|
|
$.datepicker._gotoToday = function (id) {
|
|
$(id).datepicker('setDate', new Date()).datepicker('hide').blur();
|
|
$(id).change();
|
|
};
|
|
} catch (e) {
|
|
//
|
|
}
|
|
});
|
|
|
|
function registKeyHook(keyCodes, func) {
|
|
$(document.body).keydown(function (e) {
|
|
var evt = e || window.event;
|
|
if ((typeof keyCodes == "number" || typeof keyCodes == "string") && evt.keyCode == parseInt(keyCodes)) {
|
|
if (func === undefined || func === null || typeof func !== "function") {
|
|
return;
|
|
}
|
|
func(evt);
|
|
evt.preventDefault();
|
|
return;
|
|
}
|
|
if (keyCodes instanceof Array) {
|
|
if (keyCodes.length == 2 && keyCodes[0].toLowerCase() == "ctrl") {
|
|
if (evt.ctrlKey && evt.keyCode == parseInt(keyCodes[1])) {
|
|
if (func === undefined || func === null || typeof func !== "function") {
|
|
return;
|
|
}
|
|
func(evt);
|
|
evt.preventDefault();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
//不要用这个扩展方法(因为查不到哪些地方用到所以待删除)
|
|
Array.prototype.contains = function (obj) {
|
|
var i = this.length;
|
|
while (i--) {
|
|
if (this[i] == obj) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
//去重合并arr1 为主
|
|
function MergeArray(arr1, arr2) {
|
|
var _arr = new Array();
|
|
for (var i = 0; i < arr1.length; i++) {
|
|
_arr.push(arr1[i]);
|
|
}
|
|
for (var i = 0; i < arr2.length; i++) {
|
|
var flag = true;
|
|
for (var j = 0; j < arr1.length; j++) {
|
|
if (arr2[i] == arr1[j]) {
|
|
flag = false;
|
|
break;
|
|
}
|
|
}
|
|
if (flag) {
|
|
_arr.push(arr2[i]);
|
|
}
|
|
}
|
|
return _arr;
|
|
}
|
|
|
|
//不要用这个扩展方法(因为查不到哪些地方用到所以待删除)
|
|
Array.prototype.remove = function (dx) {
|
|
if (isNaN(dx) || dx > this.length) {
|
|
return false;
|
|
}
|
|
for (var i = 0, n = 0; i < this.length; i++) {
|
|
if (this[i] != this[dx]) {
|
|
this[n++] = this[i];
|
|
}
|
|
}
|
|
this.length -= 1;
|
|
};
|
|
|
|
//var maxday = new Date(objdate.getYear(), objdate.getMonth() + 1, 0).getDate(); //当前月的最大的天数(即当月月有多少天)
|
|
// 对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;
|
|
};
|
|
|
|
String.prototype.format = function () {
|
|
var args = arguments;
|
|
return this.replace(/\{(\d+)\}/g,
|
|
function (m, i) {
|
|
return args[i];
|
|
});
|
|
};
|
|
|
|
function setIframeHeight(iframe) {
|
|
iframe && (iframe.height = $(window).height() * 4 / 5);// 500;
|
|
}
|
|
|
|
function addMonth(date, months) {
|
|
var d = new Date(date);
|
|
d.setMonth(d.getMonth() + months);
|
|
return d;
|
|
}
|
|
|
|
function showmiddlemessage(msg, time) {
|
|
return main.toast(msg, time);
|
|
}
|
|
|
|
function formatValidState(cellValue, options, rowObject) {
|
|
var imageHtml = cellValue == "2" || cellValue == "InValid" ? "无效" : "有效";
|
|
return imageHtml;
|
|
}
|
|
|
|
function SetAceDropDown(resize) {
|
|
var width = typeof resize === 'number' ? resize : 0;
|
|
$('.chosen-select').each(function () {
|
|
if ($(this).data('chosen')) return;
|
|
let w = width > 100 ? width : $(this).width();
|
|
$(this).chosen({
|
|
allow_single_deselect: true,
|
|
search_contains: true,
|
|
no_results_text: '没有匹配结果',
|
|
placeholder_text_multiple: '请选择项目',
|
|
placeholder_text_single: '请选择一项',
|
|
width: w
|
|
//width: w > 100 ? w : 120
|
|
});
|
|
});
|
|
}
|
|
|
|
//给下拉框赋值
|
|
$.fn.SetAceDropDownValue = function (val) {
|
|
this.each(function () {
|
|
$this = $(this);
|
|
$this.val(val).trigger("chosen:updated");
|
|
});
|
|
};
|
|
|
|
function gridComplete() {
|
|
$(".tooltip-options").tooltip({ html: true });
|
|
$('.tooltip-options').on('show.bs.tooltip', function () {
|
|
// alert("Alert message on show");
|
|
});
|
|
}
|
|
|
|
String.prototype.template = function () {
|
|
var args = arguments;
|
|
return this.replace(/\{(\d+)\}/g, function (m, i) {
|
|
let val = args[i];
|
|
if (typeof val === 'undefined' || val === null) {
|
|
return '';
|
|
}
|
|
return val;
|
|
});
|
|
};
|
|
|
|
function isNumber(str) {
|
|
return /^[+|-]?\d+$/.test(str);
|
|
}
|
|
|
|
function rowclick() { }
|
|
|
|
function rowdblclick() { }
|
|
|
|
function AfterInsertRow() { }
|
|
|
|
function onJqgridPaging() { } |