最近项目中公用的JS
var closeid = 1; var isneedpwd = 0; var editor1; var NoCheckUrl = 0;//适用于框架 不验证权限 !=0验证 function ErpAjax(url) { var xmlhttp; if (url.indexOf("?") > 0) { url = url + "&NowDateTimeSign=" + new Date().getTime(); } else { url = url + "?NowDateTimeSign=" + new Date().getTime(); } if (window.ActiveXObject) { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } else { xmlhttp = new XMLHttpRequest(); } var url1 = url.split('?'); var url2 = url1[1].toString().split('&'); var furl = url1[0].toString() + "?"; for (var i = 0; i < url2.length; i++) { var j = url2[i].indexOf('='); if (i == 0) { furl += url2[i].toString().substring(0, j) + "=" + encodeURIComponent(url2[i].toString().substring(j + 1)); } else { furl += "&" + url2[i].toString().substring(0, j) + "=" + encodeURIComponent(url2[i].toString().substring(j + 1)); } } //encodeURIComponent xmlhttp.open("POST", furl, false); xmlhttp.send(); return xmlhttp.responseText; } //直接执行存储过程,无确认执行提示 function Runproc(procname) { if (procname.length > 0) { var returnmsg = ErpAjax("/RunProcedure.aspx?procname=" + procname); if (returnmsg.toString() == "1") { alert("执行成功!"); } else { alert("执行失败!"); } } } //执行存储过程 有确认执行提示 function Runproc(procname, confirmstring) { if (confirm(confirmstring)) { if (procname.length > 0) { var returnmsg = ErpAjax("/RunProcedure.aspx?procname=" + procname); if (returnmsg.toString() == "1") { alert("执行成功!"); } else { alert("执行失败!"); } } } } //执行存储过程返回自定义内容 function RunprocReturnValue(procname) { if (procname.length > 0) { var returnmsg = ErpAjax("/RunProcedure.aspx?procname=" + procname + "&custom=yes"); if (returnmsg.length > 0) { return returnmsg; } else { return '操作失败'; } } } //调用示例 字符串包含双引号的 前台替换成三个@,后天在替换回来 //var paymentinforemark = $("#txt_paymentinforemark").val().replace(/"/ig, '!@!'); //var parameter = '{id:' + flowpaymentinfoid + ',paymentremark:"' + paymentinforemark + '"}'; function RunNewProc(procname, Parameter) { if (procname.length > 0) { var returnmsg = ErpAjax("/RunProcedure.aspx?Proc=" + procname + "&Parameter="+Parameter+""); if (returnmsg.length > 0) { return returnmsg; } else { return '操作失败'; } } } function Validator(form) { var valid = true; $('' + form + ' input,' + form + ' textarea').each(function () { var vd = $(this).attr("vd"); if (vd != 'undefined' && vd != undefined) { var validText = ''; for (var i = 0; i < vd.length; i++) { if ($(this).attr('combox') != undefined && $(this).attr('combox') == 'true') { validText += Validate(vd.substring(i, i + 1), $(this).combobox('getText')); } else { validText += Validate(vd.substring(i, i + 1), $(this).val()); } } if (validText != "") { $(this).addClass("error"); if ($(this).attr('combox') != undefined && $(this).attr('combox') == 'true') { $(this).combobox('setText', validText); } else if ($(this).attr('pwd') != undefined && $(this).attr('pwd') == 'pwd') { $(this).val(''); } else { $(this).val(validText); } valid = false; TextOnFocus(); //新增验证不通过时,用户操作控制 //TextOnKeyup(); // if (jQuery.browser.mozilla) { // jQuery('input,textarea').bind('keypress', TextOnKeyup); // } else { // jQuery('input,textarea').bind('keydown', TextOnKeyup); // } } } }); //var text = $('' + form + ' .error:first').val(); // $('' + form + ' .error:first').select(); // $('' + form + ' .error:first').val(text); return valid; } function TextOnKeyup(event) { if ($(this).hasClass("error")) { // $(this).removeClass("error"); } } function TextOnFocus() { $("input,textarea").bind("focus", function () { if ($(this).hasClass("error")) { $(this).removeClass("error"); if ($(this).attr('combox') == 'true') { $(this).combobox('setText', ''); } else { $(this).val(""); } } }); } function ClearValidator(form) { $('' + form + ' input,' + form + ' textarea').each(function (i) { if ($(this).hasClass("error")) { $(this).removeClass("error"); } }); } function RemoveClass(form) { $('' + form + ' input[type=text],' + form + ' textarea,' + form + ' select').each(function (i) { if ($(this).hasClass("easyui-combox")) { $(this).removeClass("error"); } }); } function Validate(type, text) { switch (type) { case "E": if (IsEmail(text)) return ""; else return "邮箱格式不正确."; case "N": if (IsInt(text)) return ""; else return "请输入整型."; case "T": if (IsDate(text)) return ""; else return "请输入正确的日期格式."; case "F": if (IsFloat(text)) return ""; else return "请输入浮点型."; case "K": if (IsNotEmpty(text)) return ""; else return "不能为空."; case "U": if (isDigit(text)) { return "用户名不能全是数字"; } else if (!isRegisterUserName(text)) { return "用户名长度至少4位最多12位"; } else return ""; case "P": if (text == '') { return ""; } else if (isDigit(text)) { return "密码不能全是数字"; } else if (!isPasswd(text)) { return "只能输入6-20个字母、数字、下划线"; } else return ""; case "Z": if (IsZFloat(text)) return ""; else return "不能为负数."; case "L": if (text == "") return ""; else if (!IsURL(text)) { return "URL错误"; } else return ""; default: return ""; break; } } function IsURL(str_url) { var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 + "|" // 允许IP和DOMAIN(域名) + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 + "[a-z]{2,6})" // first level domain- .com or .museum + "(:[0-9]{1,4})?" // 端口- :80 + "((/?)|" // a slash isn't required if there is no file name + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; var re = new RegExp(strRegex); //re.test() if (re.test(str_url)) { return (true); } else { return (false); } } //非空验证 function IsNotEmpty(str) { if (str.replace(/(^[\s]*)|([\s]*$)/g, "") == "" || str.replace(/(^[\s]*)|([\s]*$)/g, "") == "不能为空.") return false; else return true; } //整型验证 function IsInt(str) { if (str == "") return true; if (/^(\-?)(\d+)$/.test(str)) return true; else return false; } //浮点型验证 function IsFloat(str) { if (str == "") return true; if (str.indexOf(".") == -1) { return IsInt(str); } else { if (/^(\-?)(\d+)(.{1})(\d+)$/g.test(str)) return true; else return false; } } //正浮点型验证 function IsZFloat(str) { if (str == "") { return true; } if (/^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/.test(str)) return true; else return false; } //日期型验证 function IsDate(str) { if (str == "") return true; var pattern = /^([1-2]\d{3})[\/|\-](0?[1-9]|10|11|12)[\/|\-]([1-2]?[0-9]|0[1-9]|30|31)$/ig; if (!pattern.test(str)) return false; else return true; } //时间型验证 function IsTime(str) { if (str == "") return true; var pattern = /^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/; if (!pattern.test(str)) return false; else return true; } //邮件型验证 function IsEmail(str) { if (str == "") return true; if (str.charAt(0) == "." || str.charAt(0) == "@" || str.indexOf('@', 0) == -1 || str.indexOf('.', 0) == -1 || str.lastIndexOf("@") == str.length - 1 || str.lastIndexOf(".") == str.length - 1) return false; else return true; } //校验是否全由数字组成 function isDigit(s) { var patrn = /^[0-9]{1,20}$/; if (!patrn.exec(s)) return false return true } //校验登录名:只能输入5-10个以字母开头、可带数字、“_”、“.”的字串 function isRegisterUserName(s) { var patrn = /^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,12}$/; if (!patrn.exec(s)) return false return true } //校验密码:只能输入6-20个字母、数字、下划线 function isPasswd(s) { var patrn = /^(\w){6,20}$/; if (!patrn.exec(s)) return false; return true; } // serializeJson = function () { // var serializeObj = {}; // var array = $('#ProductAddForm').serializeArray(); // var str = $('#ProductAddForm').serialize(); // $(array).each(function () { // if (serializeObj[this.name]) { // if ($.isArray(serializeObj[this.name])) { // serializeObj[this.name].push(this.value); // } else { // serializeObj[this.name] = [serializeObj[this.name], this.value]; // } // } else { // serializeObj[this.name] = this.value; // } // }); // return serializeObj; // }; //表单封装 serializeObject = function (form) { var o = {}; $.each(form.serializeArray(), function (index) { if (this['value'] != undefined && this['value'].length > 0) {// 如果表单项的值非空,才进行序列化操作 if (o[this['name']]) { o[this['name']] = o[this['name']] + "," + this['value']; } else { o[this['name']] = this['value']; } } }); return o; }; var values = []; //btn_add 新增 //btn_delete 删除 //btn_edit 编辑 //btn_editlist 列表编辑 //btn_detail 查看明细 function SetRule(pagesid) { values = []; //$('.btn_finanace').css('display','block') var arr = ['btn_add', 'btn_delete', 'btn_edit', 'btn_editlist'] $.ajax({ type: "POST", async: false, // 设置同步方式 cache: false, dataType: "html", url: "/ajax/GetTreeJson.ashx", data: { PagesID: pagesid }, success: function (result) { if (result != '') { var str = result; var t = str.split(','); for (var i = 0; i < t.length; i++) { values.push(t[i]); /* 避免他将ID当成数字 */ } for (var j = 0; j < arr.length; j++) { for (var i = 0; i < values.length; i++) { if (values[i] == arr[j]) { // $(' .' + arr[i] + '').show(); //$(this).css("visibility", "visible"); $('.' + values[i]).each(function () { $(this).show(); }); continue; } } } } } }); } //判断是否有权限 function CheckRule(str) { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == str) { flag = true; } } return flag; } //判断双击事件 function IsDoubleClick() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'doubleclick') { flag = true; } } return flag; } //判断删除或取消是否需要密码 function IsNeedPwd() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'needpwd') { flag = true; } } return flag; } //判断右键菜单事件 function IsContextMenu() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'menu') { flag = true; } } return flag; } function IsEditlist() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'btn_SaveRows') { flag = true; } } return flag; } //控制报价单是否可以编辑 function IsUpControl() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'btn_sa_control') { flag = true; } } return flag; } ///控制产品管理 供应商成本和真成本 function HideColumn() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'hidecolumn') { flag = true; } } return flag; } function HideOrder() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'hidesaveorder') { flag = true; } } return flag; } function TimeRule() { var flag = false; for (var j = 0; j < values.length; j++) { if (values[j] == 'timerule') { flag = true; } } return flag; } //报价单产品新增 判断关闭前是否提示关闭 function CloseCurrentWindow(grid, form, dialog, id) { if ($('' + form + ' input[name=' + id + ']').val() != "") { parent.$.messager.confirm('询问', '数据尚未保存,确定要关闭吗?', function (r) { if (r) { $(dialog).dialog('close'); $(grid).datagrid('reload'); } }); } else { $(dialog).dialog('close') } } //替换特殊字符 function StringFilter(p_str) { if (p_str != null) { p_str = p_str.replace(/'/ig, "\'+char(39)+N\'"); p_str = p_str.replace(/--/ig, ""); //p_str = p_str.replace(/&/ig, "\'+char(38)+N\'"); //p_str = p_str.replace(/#/ig, "\'+char(35)+N\'"); //p_str = p_str.replace(/\×/ig, "<><><<><>>>>"); //p_str = p_str.replace(/\*/ig, "×"); //p_str = p_str.replace(/\\/ig, "\'+char(92)+N\'"); //p_str = p_str.replace(/\?/ig, "\'+char(63)+N\'"); ////p_str = p_str.replace(/\n/g, "\'+char(10)+N\'"); ////p_str = p_str.replace(/\r/g, "\'+char(13)+N\'"); ////p_str = p_str.replace(/\r\n/g, "\'char(13)+N\char(10)+N\'"); //p_str = p_str.replace(/( )|\s|\u00a0/g, ""); //p_str = p_str.replace(/\ +/g, ""); //p_str = p_str.replace(/\[ ]/g, ""); //p_str = p_str.replace(/\[\r\n]/g, ""); //p_str = p_str.replace(/\s+/g, ""); //p_str = p_str.replace(/\s*$|^\s*/g, ""); return p_str; } else { return ""; } } //type 0 用于数据保存后关闭 直接return true,1判断表单是否由数据 由数据提示用户 function OnDialogClose(form, hid_id, type) { var returnStr = ""; var closeflag = false; var hid_value = ""; if (document.getElementById(hid_id)) { hid_value = $('#' + hid_id).val(); } if (form == "") { closeid = 0; closeflag = true; } else { if (type != 0) { $('' + form + ' input[type=text],' + form + ' textarea').each(function (i) { var strclass = $(this).attr('class'); if (strclass == undefined || strclass.indexOf('combo') == -1) { returnStr += $(this).val(); } }); //新增 表单有数据 不关闭 hid_value=="" 并且returnStr!="" if (returnStr != "" && hid_value == "") { closeflag = false; } //新增 表单无数据 关闭 hid_value=="" 并且returnStr!="" else if (returnStr == "" && hid_value == "") { closeflag = true; } //编辑 hid_value!="" 不管表单有没有数据 直接关闭 else { closeflag = true; $('#' + hid_id).val('') } if (closeflag == false) { if (confirm('数据尚未保存,您确定要关闭吗?')) { closeflag = true; } } else { closeflag = true; } closeid = 1; return closeflag; } else { closeid = 0; return true; } } } //日历控件设置默认值 function SetDate(days) { var now = new Date(); now.setDate((now.getDate()) + days); var year = now.getFullYear(); var month = now.getMonth() + 1; var day = now.getDate(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } return year + '-' + month + '-' + day } function SetMonth(months, startdate) { var months = parseInt(months); var aa = startdate.split('-'); var now = new Date(aa[0], aa[1], aa[2]); now.setMonth(now.getMonth() + months); var year = now.getFullYear(); var month = now.getMonth(); var day = now.getDate(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if(month=="00") { year = parseInt(year) - 1; month = "12"; } return year + '-' + month + '-' + day } function SetMonth2(months, startdate) { var months = parseInt(months); var aa = startdate.split('-'); var now = new Date(aa[0], aa[1], aa[2]); now.setMonth(now.getMonth() + months); var year = now.getFullYear(); var month = now.getMonth(); var day = now.getDate(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (month == "00") { year = parseInt(year) - 1; month = "12"; } return year + '-' + month } //回车跳转 window.onload = function () { SeteasyuiTheme(); jQuery(':input:enabled').addClass('enterIndex'); var textboxes = jQuery('.enterIndex'); if ($.support.mozilla) { jQuery(textboxes).bind('keypress', CheckForEnter); } else { jQuery(textboxes).bind('keydown', CheckForEnter); } }; function SeteasyuiTheme() { var easyuiTheme = $.cookie("easyuiTheme"); var $easyuiTheme = $('#easyuiTheme'); if (easyuiTheme != null && easyuiTheme != undefined) { var url = $easyuiTheme.attr('href'); var href = url.substring(0, url.indexOf('themes')) + 'themes/' + easyuiTheme + '/easyui.css'; $easyuiTheme.attr('href', href); } else { $easyuiTheme.attr('href', "/Scripts/easyui/themes/default/easyui.css"); } $('#mm1 .menu-line').remove(); } function CheckForEnter(event) { if (event.keyCode == 13 && $(this).attr('type') != 'submit' && $(this).attr('type') != 'reset' && $(this).attr('type') != 'hidden' && $(this).attr('type') != 'textarea' && $(this).attr('type') != undefined) { var i = $('.enterIndex').index($(this)); var n = $('.enterIndex').length; if (i < n - 1) { if ($(this).attr('type') != 'radio') { NextDOM($('.enterIndex'), i); } else { var last_radio = $('.enterIndex').index($('.enterIndex[type=radio][name=' + $(this).attr('name') + ']:last')); NextDOM($('.enterIndex'), last_radio); } } return false; } } function NextDOM(myjQueryObjects, counter) { if (myjQueryObjects.eq(counter + 1)[0].disabled) { NextDOM(myjQueryObjects, counter + 1); } else if (myjQueryObjects.eq(counter + 1).attr('type') == 'hidden') { NextDOM(myjQueryObjects, counter + 1); } else if (myjQueryObjects.eq(counter + 1).attr('readonly') == 'readonly') { NextDOM(myjQueryObjects, counter + 1); } else { if (myjQueryObjects.eq(counter + 1).attr('type') == 'button') { myjQueryObjects.eq(counter + 1).trigger('click'); } else { myjQueryObjects.eq(counter + 1).focus(); myjQueryObjects.eq(counter + 1).trigger('focus'); myjQueryObjects.eq(counter + 1).trigger('select'); } } } //删除或取消发工资的时候 弹出输入密码 确认后再删除或取消发工资 function DelByPwd(pagesid, pwd, proc) { if (pwd == '') { $.messager.alert('提示', '请输入密码', 'error'); isneedpwd = 1; return; } $.ajax({ type: "POST", async: false, // 设置同步方式 cache: false, dataType: "json", data: { "pagesid": pagesid, "PassWord": pwd }, url: "/ajax/Product/DeleteNeedPwd.ashx", success: function (result) { if (result[0].success) { $('#ShowPwd').dialog('close') isneedpwd = 0; parent.$.messager.confirm('询问', '确定要执行吗?', function (r) { if (r) { $.messager.alert('提示', RunprocReturnValue(proc), 'ok'); grid.datagrid('reload'); } }); } else { $.messager.alert('提示', '密码错误', 'error'); isneedpwd = 1; return; } }, error: function () { $.messager.alert('提示', '出错了', 'error'); isneedpwd = 1; return; } }); } //短日期比较 function duibi(a, b) { var arr = a.split("-"); var starttime = new Date(arr[0], arr[1], arr[2]); var starttimes = starttime.getTime(); var arrs = b.split("-"); var lktime = new Date(arrs[0], arrs[1], arrs[2]); var lktimes = lktime.getTime(); if (starttimes >= lktimes) { return false; } else return true; } function GetDatetime(a, b) { var arr = a.split("-"); var starttime = new Date(arr[0], arr[1], arr[2]); return starttime; } function DATEDIFF(beginTime, endTime) { // var beginTime = "2009-09-21 00:00:00"; //var endTime = "2009-09-21 00:00:01"; var beginTimes = beginTime.substring(0, 10).split('-'); var endTimes = endTime.substring(0, 10).split('-'); beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19); endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19); var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000 / 24; return a; } //长日期js时间比较(yyyy-mm-dd hh:mi:ss) function comptime(beginTime, endTime) { // var beginTime = "2009-09-21 00:00:00"; //var endTime = "2009-09-21 00:00:01"; var beginTimes = beginTime.substring(0, 10).split('-'); var endTimes = endTime.substring(0, 10).split('-'); beginTime = beginTimes[1] + '-' + beginTimes[2] + '-' + beginTimes[0] + ' ' + beginTime.substring(10, 19); endTime = endTimes[1] + '-' + endTimes[2] + '-' + endTimes[0] + ' ' + endTime.substring(10, 19); var a = (Date.parse(endTime) - Date.parse(beginTime)) / 3600 / 1000; if (a < 0) { return false; //alert("endTime小!"); } else if (a > 0) { //alert("endTime大!"); return true; } else if (a == 0) { // alert("时间相等!"); return true; } else { //return 'exception' return false; } } //页面禁用返回键 但文本框不失效 document.documentElement.onkeydown = function (evt) { //var b = !!evt, oEvent = evt || window.event; // if (oEvent.keyCode == 8) { // var node = b ? oEvent.target : oEvent.srcElement; // var reg = /^(input|textarea)$/i, regType = /^(text|textarea)$/i; // if (!reg.test(node.nodeName) || !regType.test(node.type) || node.readOnly || node.disabled) { // if (b) { // oEvent.stopPropagation(); // } // else { // oEvent.cancelBubble = true; // oEvent.keyCode = 0; // oEvent.returnValue = false; // } // } // } //获取事件对象 var elem = event.relatedTarget || event.srcElement || event.target || event.currentTarget; if (event.keyCode == 8) {//判断按键为backSpace键 //获取按键按下时光标做指向的element var elem = event.srcElement || event.currentTarget; //判断是否需要阻止按下键盘的事件默认传递 var name = elem.nodeName; if (name != 'INPUT' && name != 'TEXTAREA') { return _stopIt(event); } var type_e = elem.type.toUpperCase(); if (name == 'INPUT' && (type_e != 'TEXT' && type_e != 'TEXTAREA' && type_e != 'PASSWORD' && type_e != 'FILE')) { return _stopIt(event); } if (name == 'INPUT' && (elem.readOnly == true || elem.disabled == true)) { return _stopIt(event); } } } function _stopIt(e) { if (e.returnValue) { e.returnValue = false; } if (e.preventDefault) { e.preventDefault(); } return false; } function triggerPwd(domid) { $(domid).trigger('click') } $(function () { var url = document.location.search; var Request = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { Request[strs[i].split("=")[0]] = strs[i].split("=")[1]; } } if (NoCheckUrl == 0) { URLValidation(); } if (Request["pagesid"] != undefined) { //写入浏览记录 // RunprocReturnValue('SP_UserTraffic ' + Request["pagesid"] + ',' + $('#hid_userid').val() + ''); //$.post('/RunProcedure.aspx', { // 'pagesid': pagesid, 'guid': Math.random() //}, function (result) { //}, 'text'); $.post('/RunProcedure.aspx', { 'pagesid': Request["pagesid"], 'guid': Math.random() }, function (result) { if (result == "0") { } }, 'text'); var str_HelpHtml = "<table border ='0' cellpadding ='0' cellspacing ='0' style ='width:1%; position:relative; z-index:100;clear:both ;float:right;text-align:right'>"; str_HelpHtml += "<tr>"; str_HelpHtml += "<td style ='text-align:right;padding-right:0px;'><a class='help_icon' style ='cursor:help' href='#' onclick ='ShowHelpBox(" + Request["pagesid"] + ")'></a></td>"; str_HelpHtml += "</tr>"; str_HelpHtml += "</table>"; str_HelpHtml += "<div class=\"easyui-dialog\" id='ShowHelp' data-options=\"maximizable:true,width: 990, closed: true,cache: false,modal: true\"><a id=\"help\" href=\"javascript:void(0)\" class=\"easyui-linkbutton\" onclick=\"SaveHelpRemark()\">保存</a> <textarea id=\"content1\" cols=\"100\" rows=\"8\" style=\"width:95%;height:550px;visibility:hidden;\" ></textarea> </div> "; // $(str_HelpHtml).prependTo("body"); $('body').append(str_HelpHtml); var headhtml = "<link rel=\"stylesheet\" href=\"/scripts/kindeditor/themes/default/default.css\" />"; headhtml += " <link rel=\"stylesheet\" href=\"/scripts/kindeditor/plugins/code/prettify.css\" />"; headhtml += " <script charset=\"utf-8\" src=\"/scripts/kindeditor/kindeditor.js\"></script>"; headhtml += " <script charset=\"utf-8\" src=\"/scripts/kindeditor/lang/zh_CN.js\"></script>"; headhtml += " <script charset=\"utf-8\" src=\"/scripts/kindeditor/plugins/code/prettify.js\"></script>"; // headhtml += " <script> "; //headhtml += " KindEditor.ready(function (K) { "; //headhtml += " var editor1 = K.create('#content1', { "; //headhtml += " cssPath: '/scripts/kindeditor/plugins/code/prettify.css', "; //headhtml += " uploadJson: '/scripts/kindeditor/asp.net/upload_json.ashx', "; //headhtml += " fileManagerJson: '/scripts/kindeditor/asp.net/file_manager_json.ashx', "; //headhtml += " allowFileManager: true, "; //headhtml += " onBeforeClose: function (event, ui) { "; //headhtml += " KindEditor.remove('#content1'); "; //headhtml += " },"; //headhtml += " afterCreate: function () { "; //headhtml += " var self = this; "; //headhtml += " K.ctrl(document, 13, function () { "; //headhtml += " self.sync(); "; //headhtml += " K('form[name=example]')[0].submit(); "; //headhtml += " }); "; //headhtml += " K.ctrl(self.edit.doc, 13, function () { "; //headhtml += " self.sync(); "; //headhtml += " K('form[name=example]')[0].submit(); "; //headhtml += " }); "; //headhtml += " } "; //headhtml += " }); "; //headhtml += " prettyPrint(); "; //headhtml += " }); "; //headhtml += " </script> "; $('head').append(headhtml); } $.ajax({ type: "POST", async: false, // 设置同步方式 cache: false, dataType: "json", url: '/ajax/user/UserIno.ashx?username=2', success: function (result) { if (result[0].success) { $.messager.alert('提示', '您使用了系统默认密码,请前往用户管理 修改密码!!!', 'warning'); } } }); }) function ShowHelpBox(PageID) { $('#help').linkbutton({ iconCls: 'icon-ok' }); //$('.ke-statusbar').show(); // var url = "/help.aspx?PageID=" + PageID + ""; //var url = "/BarCodes/BarCode.aspx" $('#ShowHelp').dialog({ title: '帮助文档', width: $(this).width() - 150, height: $(this).height() - 50, closed: false, cache: false, // href: url, modal: true, onBeforeClose: function () { // 关闭Dialog前移除编辑器 KindEditor.remove('#content1'); }, onOpen: function () { editor1 = KindEditor.create('#content1', { cssPath: '/scripts/kindeditor/plugins/code/prettify.css', uploadJson: '/scripts/kindeditor/asp.net/upload_json.ashx', fileManagerJson: '/scripts/kindeditor/asp.net/file_manager_json.ashx', allowFileManager: true, afterCreate: function () { var self = this; KindEditor.ctrl(document, 13, function () { self.sync(); KindEditor('form[name=example]')[0].submit(); }); KindEditor.ctrl(self.edit.doc, 13, function () { self.sync(); KindEditor('form[name=example]')[0].submit(); }); } }); prettyPrint(); } }); $.ajax({ type: "POST", async: false, // 设置同步方式 cache: false, dataType: "text", url: "/ajax/MenuList.ashx", data: { "PagesID": PageID, 'ActionName': 'HelpRemark' }, success: function (result) { editor1.html(result); } }); } function SaveHelpRemark() { var url = document.location.search; var Request = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { Request[strs[i].split("=")[0]] = strs[i].split("=")[1]; } } if (Request["pagesid"] != undefined) { $.ajax({ type: "POST", async: false, // 设置同步方式 cache: false, dataType: "text", url: "/ajax/MenuList.ashx", data: { "PagesID": Request["pagesid"], 'ActionName': 'SaveHelpRemark', 'HelpRemark': editor1.html() }, success: function (result) { parent.$.messager.alert('提示', result, 'ok'); } }); } else { parent.$.messager.alert('提示', '抱歉出错了!', 'error'); } } /** * 获取指定月的最后一天 */ function getMonthLastDay() { var now = new Date(); now.setDate((now.getDate())); var year = now.getFullYear(); var month = now.getMonth() + 1; var day = now.getDate(); var newnew_date = new Date(year, month, 1); //取当年当月中的第一天 var newday = (new Date(newnew_date.getTime() - 1000 * 60 * 60 * 24)).getDate();//获取当月最后一天日期 //newdate.setDate((newdate.getDate())); if (month < 10) { month = "0" + month; } if (newday < 10) { newday = "0" + newday; } return year + '-' + month + '-' + newday } /** * 获取指定月份的第一天 */ function getMonthFirstDay(m) { var now = new Date(); now.setDate((now.getDate())); var year = now.getFullYear(); var month = now.getMonth() + 1; if (month < 3) { if (month == 1) { month == 11 } else if (month == 2) { month = 12 } year = year - 1; } else { if (month == 3) { month = 1 } else { month = month - m; } } var day = 1; if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } return year + '-' + month + '-' + day } function ExportExcel(strXlsName, html) { var f = $('<form action="/export.aspx" method="post" id="fm1"></form>'); var i = $('<input type="hidden" id="txtContent" name="txtContent" />'); var l = $('<input type="hidden" id="txtName" name="txtName" />'); i.val(html); i.appendTo(f); l.val(encodeURIComponent(strXlsName)); l.appendTo(f); f.appendTo(document.body).submit(); document.body.removeChild(f); } function treeChecked(selected, sharettt) { var t = $(sharettt).combotree('tree'); var roots = t.tree('getRoots'); //返回tree的所有根节点数组 if (selected.checked) { for (var i = 0; i < roots.length; i++) { var node = t.tree('find', roots[i].id); //查找节点 t.tree('check', node.target); //将得到的节点选中 } } else { for (var i = 0; i < roots.length; i++) { var node = t.tree('find', roots[i].id); t.tree('uncheck', node.target); } } } // strPrintName 打印任务名 // printDatagrid 要打印的datagrid function CommonPrint(printDatagrid, type) { var tableString = '<table cellspacing="0" class="pb">'; var frozenColumns = printDatagrid.datagrid("options").frozenColumns; // 得到frozenColumns对象 var columns = printDatagrid.datagrid("options").columns; // 得到columns对象 var nameList = ''; // 载入title if (typeof columns != 'undefined' && columns != '') { $(columns).each(function (index) { tableString += '\n<tr>'; if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') { for (var i = 0; i < frozenColumns[index].length; ++i) { if (frozenColumns[index][i].field != "id" && frozenColumns[index][i].field != "cid" && frozenColumns[index][i].field != "pid") { // if (!frozenColumns[index][i].hidden) { tableString += '\n<th width="' + frozenColumns[index][i].width + '"'; if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) { tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"'; } if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) { tableString += ' colspan="' + frozenColumns[index][i].colspan + '"'; } if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '') { nameList += ',{"f":"' + frozenColumns[index][i].field + '", "a":"' + frozenColumns[index][i].align + '"}'; } tableString += '>' + frozenColumns[0][i].title + '</th>'; // } } } } for (var i = 0; i < columns[index].length; ++i) { if (columns[index][i].field != "id" && columns[index][i].field != "cid" && columns[index][i].field != "pid") { // if (!columns[index][i].hidden) { tableString += '\n<th width="' + columns[index][i].width + '"'; if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) { tableString += ' rowspan="' + columns[index][i].rowspan + '"'; } if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) { tableString += ' colspan="' + columns[index][i].colspan + '"'; } if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '') { nameList += ',{"f":"' + columns[index][i].field + '", "a":"' + columns[index][i].align + '"}'; } tableString += '>' + columns[index][i].title + '</th>'; // } } } tableString += '\n</tr>'; }); } // 载入内容 var rows = printDatagrid.datagrid("getRows"); // 这段代码是获取当前页的所有行 var nl = eval('([' + nameList.substring(1) + '])'); for (var i = 0; i < rows.length; ++i) { tableString += '\n<tr>'; $(nl).each(function (j) { var e = nl[j].f.lastIndexOf('_0'); tableString += '\n<td'; if (nl[j].a != 'undefined' && nl[j].a != '') { tableString += ' style="text-align:' + nl[j].a + ';"'; } tableString += '>'; if (e + 2 == nl[j].f.length) { tableString += rows[i][nl[j].f.substring(0, e)]; } else tableString += rows[i][nl[j].f]; tableString += '</td>'; }); tableString += '\n</tr>'; } tableString += '\n</table>'; var tt = /\&/g; //匹配&号 var tt2 = /\?/g; //匹配问号 if (type == 1) { if (navigator.userAgent.indexOf("Chrome") > 0) { $('#ShowOpenWindow').html(""); $('#ShowOpenWindow').append("<div><iframe src='../Purchase/Cargoprint.aspx?revalue=" + tableString.replace(tt, "").replace(tt2, "") + "' style='width:99%;margin: 0px; height: 400px;' ></iframe></div>"); $('#ShowOpenWindow').window('refresh').window('open'); $('#ShowOpenWindow').window('close'); } else { window.showModalDialog("../print.html", tableString, "location:No;status:No;help:No;dialogWidth:1200px;dialogHeight:600px;scroll:auto;"); } } else { var f = $('<form action="/export.aspx" method="post" id="fm1"></form>'); var i = $('<input type="hidden" id="txtContent" name="txtContent" />'); var l = $('<input type="hidden" id="txtName" name="txtName" />'); i.val(tableString); i.appendTo(f); l.val(encodeURIComponent(ordernumber)); l.appendTo(f); f.appendTo(document.body).submit(); document.body.removeChild(f); } } ///子页面添加tabs function ToUrl(url, pageName) { var jq = top.jQuery; var tabs = jq('#worktab'); var src = url + "&NowDateTimeSign =" + Math.random(); //var isreloadid = node.attributes.isreloadid; var opts = { title: pageName, closable: true, //iconCls: node.iconCls, content: '<iframe id="ifm_frame" src="' + src + '" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>', border: false, fit: true, index:0 //id: isreloadid//暂时将是否重新刷新页面放在ID上 }; if (tabs.tabs('exists', opts.title)) { if (opts.title != '通知中心') { tabs.tabs('add', opts); } else { tabs.tabs('select', '通知中心'); } } else{ tabs.tabs('add', opts); } tabClose(); tabCloseEven(); } function URLValidation() { var url1 = document.location.host; var url = document.URL; var a = url.substring(url.indexOf(url1) + url1.length, url.length); var urlname = ""; if (a.indexOf('?') != -1) { urlname = a.substring(0, a.indexOf('?')); } else { urlname = a; } $.post('/ajax/GetTreeJson.ashx', { 'UrlName': urlname, 'guid': Math.random() }, function (result) { if (result == "0") { alert('您无此页面权限'); window.location.href = "/index.html"; } }, 'text'); } function HtmlReplace(str) { if (str != "") { str = str.replace(/\'/g, "") // -> ' 替换成 \' // str = str.replace(/\"/g, "\\\"") // " 替换成\" //注:适用于 onclick='Test("数字双音\"")' //这种写法 // str = str.replace(/\"/g, """) //" 替换成 " //注:适用于onclick="Test('数字双音"')" 建议写法 // str = str.replace(/</g, "\\\<") // < 替换成\< // str = str.replace(/>/g, "\\\>") // > 替换成\> } else { str = '' } return str; } //数组去掉重复的 function unique(arr) { var result = [], hash = {}; for (var i = 0, elem; (elem = arr[i]) != null; i++) { if (!hash[elem]) { if (elem != '' && elem !== ' ') { result.push(elem); hash[elem] = true; } } } return result; } function funcChina(obj) { if (/.*[\u4e00-\u9fa5]+.*$/.test(obj)) { return false; } return true; } function LoadMusic() { var ua = navigator.userAgent.toLowerCase(); if (ua.match(/msie ([\d.]+)/)) { jQuery('#__alert_sound').html('<object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"><param name="AutoStart" value="1" /><param name="Src" value="/music/1.wav" /></object>'); } else if (ua.match(/firefox\/([\d.]+)/)) { jQuery('#__alert_sound').html('<embed src="/music/1.wav" type="audio/mp3" hidden="true" loop="false" mastersound></embed>'); } else if (ua.match(/chrome\/([\d.]+)/)) { jQuery('#__alert_sound').html('<audio src="/music/1.wav" type="audio/mp3" autoplay=”autoplay” hidden="true"></audio>'); } else if (ua.match(/opera.([\d.]+)/)) { jQuery('#__alert_sound').html('<embed src="/music/1.wav" hidden="true" loop="false"><noembed><bgsounds src="/sounds/alert/1.mp3"></noembed>'); } else if (ua.match(/version\/([\d.]+).*safari/)) { jQuery('#__alert_sound').html('<audio src="/music/1.wav" type="audio/mp3" autoplay=”autoplay” hidden="true"></audio>'); } else { jQuery('#__alert_sound').html('<embed src="/music/1.wav" type="audio/mp3" hidden="true" loop="false" mastersound></embed>'); } } function GoToUrl(url, pageName, ID,UserID, TypeID) { if (TypeID == 1) { RunprocReturnValue('sp_Notice_Update ' + ID + "," + UserID) } var jq = top.jQuery; var tabs = jq('#worktab'); var src = url + "&NowDateTimeSign =" + Math.random(); //var isreloadid = node.attributes.isreloadid; var opts = { title: pageName, closable: true, //iconCls: node.iconCls, content: '<iframe id="ifm_frame" src="' + src + '" allowTransparency="true" style="border:0;width:100%;height:99%;" frameBorder="0"></iframe>', border: false, fit: true, //id: isreloadid//暂时将是否重新刷新页面放在ID上 }; tabs.tabs('add', opts); } function tabClose() { /*双击关闭TAB选项卡*/ $(".tabs-inner").dblclick(function () { var subtitle = $(this).children(".tabs-closable").text(); $('#worktab').tabs('close', subtitle); }) /*为选项卡绑定右键*/ $(".tabs-inner").bind('contextmenu', function (e) { $('#mm').menu('show', { left: e.pageX, top: e.pageY }); var subtitle = $(this).children(".tabs-closable").text(); $('#mm').data("currtab", subtitle); $('#worktab').tabs('select', subtitle); return false; }); $('#mm .menu-line').remove(); } //绑定右键菜单事件 function tabCloseEven() { $('#mm').menu({ onClick: function (item) { closeTab(item.id); } }); return false; } //创建Frame function createFrame(url) { var s = '<iframe scrolling="auto" frameborder="0" src="' + url + '" style="width:100%;height:100%;"></iframe>'; return s; } //关闭tab function closeTab(action) { var alltabs = $('#worktab').tabs('tabs'); var currentTab = $('#worktab').tabs('getSelected'); var allTabtitle = []; $.each(alltabs, function (i, n) { allTabtitle.push($(n).panel('options').title); }) switch (action) { case "refresh": var iframe = $(currentTab.panel('options').content); var src = iframe.attr('src'); $('#worktab').tabs('update', { tab: currentTab, options: { content: createFrame(src) } }) break; case "close": var currtab_title = currentTab.panel('options').title; $('#worktab').tabs('close', currtab_title); break; case "closeall": $.each(allTabtitle, function (i, n) { //if (n != onlyOpenTitle) { // $('#worktab').tabs('close', n); //} $('#worktab').tabs('close', n); }); break; case "closeother": var currtab_title = currentTab.panel('options').title; $.each(allTabtitle, function (i, n) { //if (n != currtab_title && n != onlyOpenTitle) { // $('#worktab').tabs('close', n); //} if (n != currtab_title) { $('#worktab').tabs('close', n); } }); break; case "closeright": var tabIndex = $('#worktab').tabs('getTabIndex', currentTab); if (tabIndex == alltabs.length - 1) { $.messager.alert('提示', '右侧已经没有了', 'error'); return false; } $.each(allTabtitle, function (i, n) { if (i > tabIndex) { //if (n != onlyOpenTitle) { // $('#worktab').tabs('close', n); //} $('#worktab').tabs('close', n); } }); break; case "closeleft": var tabIndex = $('#worktab').tabs('getTabIndex', currentTab); if (tabIndex == 0) { $.messager.alert('提示', '左侧已经没有了', 'error'); return false; } $.each(allTabtitle, function (i, n) { if (i < tabIndex) { //if (n != onlyOpenTitle) { // $('#worktab').tabs('close', n); //} $('#worktab').tabs('close', n); } }); break; case "exit": $('#closeMenu').menu('hide'); break; } }
//JS 比较两个日期的秒数
var nowTime=new Date();
var oldTime=loginInfo.dateTime;//以前保存的一个时间
oldTime=new Date(oldTime);
(nowTime.getTime()-oldTime.getTime())/(1000)