博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Javascript Utils.js
阅读量:6289 次
发布时间:2019-06-22

本文共 8410 字,大约阅读时间需要 28 分钟。

\
var Utils ={//字符串格式化StringFormat: function () {if (arguments.length == 0)return null;var str = arguments[0];for (var i = 1; i < arguments.length; i++) {var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');str = str.replace(re, arguments[i]);}return str;},// val为经json直接序列化后的C#的DateTime类型的数据FormatTime: function (val, format) {if (!val) {return "";}var re = /-?\d+/;var m = re.exec(val);var d = new Date(parseInt(m[0]));// 按【2012-02-13 09:09:09】的格式返回日期var defaultFormat = "yyyy-MM-dd hh:mm:ss";if (format && typeof format == "string") {defaultFormat = format;}return d.Format(defaultFormat);},//判断是否是有效的日期格式字符串IsDataString: function (strData) {/// /// 编辑/新增/// /// 需要校验的字符串/// 
//日期格式正则var dataFilter = /^([1-9]\d{3}-((0?[1-9])|(1[0-2]))-((0[1-9])|([1-2]?\d)|(3[0-1])))?$/return dataFilter.test(strData);},//判断是否是有效的日期时间格式字符串IsDataTimeString: function (strDataTime) {/// /// 判断是否是有效的日期时间格式字符串/// /// 需要校验的字符串///
//日期时间格式正则var timeFilter = /^[1-9][0-9]-(0?[1-9]|1[0|1|2])-(0?[1-9]|[1|2][0-9]|3[0|1])s(0?[1-9]|1[0-9]|2[0-3]):(0?[0-9]|[1|2|3|4|5][0-9]):(0?[0-9]|[1|2|3|4|5][0-9])$/;return timeFilter.test(strDataTime);},/// ///将时间转换为c#需要的反序列化的格式 (默认处理时区)/// /// 时间/// bool类型,true处理时区,false处理时区GetDateSerializeString: function (strDateTime,isDoOffset) {var dataFilter = /^([1-9]\d{3}-((0?[1-9])|(1[0-2]))-((0[1-9])|([1-2]?\d)|(3[0-1])))$/if (dataFilter.test(strDateTime)) {strDateTime = strDateTime.replace(/-/g, "/");var localOffset = new Date().getTimezoneOffset() * 60000;//时区偏差if (typeof (localOffset) != undefined && isDoOffset == false) {localOffset = 0;}return "\/Date(" + (new Date(strDateTime).valueOf() - localOffset) + ")\/";}else {return null;}},//文字超长省略显示OverflowFormatter: function (value) {return "
" + $.trim(value) + "
"},//json时间格式转字符串JsonDateFormatter: function (strJsonTime) {if (!strJsonTime || strJsonTime == "") {return "";}var date;//newtonsoft类型if (strJsonTime.indexOf("T") > 0) {strJsonTime = strJsonTime.replace("T", " ");date = new Date(Date.parse(strJsonTime.replace(/-/g, "/")));}else if (strJsonTime.indexOf("Date") > 0) {//微软类型var re = /-?\d+/;var m = re.exec(strJsonTime);date = new Date(parseInt(m[0]));}if (date) {return date.Format("yyyy-MM-dd");}else {return "";}},//配置jqGrid表格根据页面宽度动态适配,两个参数分别为表格id与表格所在父容器的id,通过动态匹配父容器宽度来实现//第三个参数为宽度偏移值,为了适配不同的页面SetGridWidthDynamic: function (tableId, parentContainerId, offsetValue) {if ($.browser.msie && parseInt($.browser.version, 10) < 8) {return;}$(window).resize(function () {Utils.SetGridWidth(tableId, parentContainerId, offsetValue);});},//手动触发表格的宽度自适应SetGridWidth: function (tableId, parentContainerId, offsetValue) {var grid = $(tableId);if (grid && grid.length == 1) {var parentWidth = $(parentContainerId).width();if (parentWidth > 1680) { //避免出现不断拉宽的问题return;}var gridWidth = grid.width();if (parentWidth > 0 && Math.abs(parentWidth - gridWidth) > 10) {grid.setGridWidth(parentWidth - offsetValue);}}},//设置jqGrid表格中Tip提示框//fromColIndex: 从哪一列开始进行Tip提示,必填//toColIndex: Tip提示到哪一列截止,非必填,如果不填表示从fromColIndex开始到最后所有的列//注:序号需要考虑隐藏列,从1开始,同时需要引入tooltip插件SetCellTipInfo: function (tableId, fromColIndex, toColIndex) {var tableObj = $("#" + tableId);if (!tableObj) {return;}toColIndex = (!toColIndex) ? 100 : toColIndex;tableObj.find("tr").each(function () {if (!$(this).hasClass("jqgfirstrow")) {$(this).find("td").each(function (index, item) {if (index >= fromColIndex && index <= toColIndex) {if ($(item).find("div").length > 0) {var oldContent = $(item).find("div").html();var newContent = Utils.StringFormat("
{1}
", $(item).find("div").attr("title"), $.trim(oldContent));$(item).empty().html(newContent);} else {var oldContent = $(item).html();var newContent = Utils.StringFormat("
{1}
", $(item).attr("title"), $.trim(oldContent));$(item).removeAttr("title").empty().html(newContent);}}});}});$(".tipClass").tooltip({ track: true, delay: 0, showURL: false, showBody: " - ", fade: 300 });},//设置左侧树的高度与右侧区域相同的高度,offsetHeight为局部调整高度SetTreeHeight: function (treeId, rightDivId, minHeight, offsetHeight) {var treeH = $(treeId).height();var rightH = $(rightDivId).height();//修改左侧树动态高度逻辑if (rightH < minHeight) {treeH = minHeight;offsetHeight = 0;}else {treeH = rightH;}$(treeId).height(treeH - offsetHeight);},// 复制对像Clone: function (myObj) {if (typeof (myObj) != 'object') { return myObj; }if (myObj == null) { return myObj; }var myNewObj = new Object();for (var i in myObj) {myNewObj[i] = this.Clone(myObj[i]);}return myNewObj;},//日志打印Log: function (msg) {if (typeof console != undefined) {var str = Utils.StringFormat("【{0}】{1}", (new Date()).Format("yyyy-MM-dd hh:mm:ss"), msg);console.log(str);}},HtmlEncode: function (str) {var s = "";if (str.length == 0)return "";s = str.replace(/&/g, "&");s = s.replace(//g, ">");s = s.replace(/ /g, " ");s = s.replace(/\'/g, "'");s = s.replace(/\"/g, """);return s;},HtmlDecode: function (str) {var s = "";if (str.length == 0)return "";s = str.replace(/&/g, "&");s = s.replace(/</g, "<");s = s.replace(/>/g, ">");s = s.replace(/ /g, " ");s = s.replace(/'/g, "\'");s = s.replace(/"/g, "\"");return s;},// 导出文件DownloadFile: function (url) {if (navigator.userAgent.indexOf("MSIE 8.0") > 0 || navigator.userAgent.indexOf("MSIE 7.0") > 0) {location.href = url;}else {var frame = $("#__ipalDownloadFrame");if (frame.length == 0) {frame = $("
 

 

 

转载地址:http://ghzta.baihongyu.com/

你可能感兴趣的文章
Python多线程
查看>>
写作环境搭建(git+github+markdown+jekyll)
查看>>
Codeforces Round #443 (Div. 2) C. Short Program
查看>>
flash builder4的序列号(阻止adobe更新)
查看>>
Android横竖屏切换的生命周期
查看>>
python之生成随机密码
查看>>
jekens介绍及服务搭建
查看>>
26. Remove Duplicates from Sorted Array*(快慢指针)
查看>>
bzoj1096[ZJOI2007]仓库建设
查看>>
bzoj1745[Usaco2005 oct]Flying Right 飞行航班*
查看>>
vue数组检测更新问题
查看>>
7月,带你阅读图灵原创图书以及上榜新书
查看>>
【原】无脑操作:Gitblit服务器搭建及IDEA整合Git使用
查看>>
python基础学习笔记
查看>>
shell编程
查看>>
MongoDB 主从同步设置
查看>>
百度地图之控件
查看>>
js keycode大全
查看>>
颜色空间系列4: RGB和YDbDr颜色空间的转换及优化算法
查看>>
Unity C# 设计模式(七)适配器模式
查看>>