首页 > 学院 > 开发设计 > 正文

JS工具类

2019-11-08 03:06:27
字体:
来源:转载
供稿:网友
/*+++++++++++++++++++++++++++++++++++++++ chat:V1.0+ email:58293177@QQ.com+ date:2016-06-24+ author:Tyrael++++++++++++++++++++++++++++++++++++++*///调试var debug = true;//打开页面时间var openTime = new Date();// ===== 弹出窗口 ===== ///*+++++++++++++++++++++++++++++++++++++ onclick = "popup('******.jsp?id=&name=','窗口名称');"++++++++++++++++++++++++++++++++++++ */function popup(JspName,WindowName){var top=(screen.height-480)/2;    var left=(screen.width-640)/2;    var attr="width="+700+",height="+530+",location=0,menubar=0,scrollbars=1,status=0,resizable=0,top="+top+",left="+left;    var mywin=window.open(JspName, WindowName, attr);    mywin.focus();}//===== 弹出说明 ===== ///*+++++++++++++++++++++++++++++++++++++ onclick = "show(message);"++++++++++++++++++++++++++++++++++++ */function show(message){alert(message);}// ===== 改变TR颜色 ===== ///*+++++++++++++++++++++++++++++++++++++ onmousemove="changeTrColor(this)"++++++++++++++++++++++++++++++++++++ */function changeTrColor(obj){ $(".display tr").on("mouSEOver", function() {$(this).CSS({"background-color" : "rgb(196,196,255)"});});$(".display tr").on("mouseout", function() {$(this).css({"background-color" : "rgb(245,245,245)"});});}//===== TR点击改变颜色 ===== ///*++++++++++++++++++++++++++++++++++++ + 1.传递tr对象改变颜色+  2.js调用clickTrColor("表格名称")  重置所有tr颜色+ onclick="clickTrColor(this)"++++++++++++++++++++++++++++++++++++ */function clickTrColor(obj){ var table = obj.parentNode;if(table != undefined && table.tagName.toLowerCase() == "tbody".toLowerCase()){for ( var i = 0; i < table.rows.length; i++) {if (table.rows[i] == obj) {table.rows[i].style.backgroundColor = "#C4C4FF";} else {table.rows[i].style.backgroundColor = "#FFFFFF";}}}else{//重置TABLE颜色$("."+obj+" tr").css("background-color","#FFFFFF");}}//===== 获取浏览器内核 ===== ///*++++++++++++++++++++++++++++++++++++ +  本框架支持IE8.0及以上版本,火狐,谷歌+ getBrowser()++++++++++++++++++++++++++++++++++++ */function getBrowser(){var $Browser = navigator.userAgent.toLowerCase() ;var $IE = /msie [/d.]+;/gi;//IEif($Browser.indexOf("msie") > 0){var browser = $Browser.match($IE) ;var verinfo = (browser+"").replace(/[^0-9.]/ig,"");if(Number(verinfo)<8.0){nWarning("您目前的浏览器版本过低,请升级浏览器版本!");}}}//===== 元素变为不可编辑 ===== ///*+++++++++++++++++++++++++++++++++++++ noEdit()+ 页面元素不可编辑++++++++++++++++++++++++++++++++++++ */function noEdit(){$("file").attr("disabled", true);  $("input").attr("disabled",true);$("select").attr("disabled",true);$("select").trigger("liszt:updated");}//===== 元素变为可编辑 ===== ///*+++++++++++++++++++++++++++++++++++++ canEdit()+ 页面元素可编辑++++++++++++++++++++++++++++++++++++ */function canEdit(){$("file").attr("disabled", false);  $("input").attr("disabled",false);$("select").attr("disabled",false);$("select").trigger("liszt:updated");}//===== 可编辑页面的按钮控制(默认状态) =====///*+++++++++++++++++++++++++++++++++++++ 默认状态 添加,修改 2个按钮可用+ + 01.点击添加,保存和取消可用,添加,修改不可用+ 02.点击修改,保存和取消可用,添加,修改不可用+ defaultButton()++++++++++++++++++++++++++++++++++++ */function defaultButton(){$(".insert").show();$(".update").show();$(".save").hide();$(".cancel").hide();$(".other").show();}//===== 可编辑页面的按钮控制(编辑状态) =====///*+++++++++++++++++++++++++++++++++++++ ++ editButton()++++++++++++++++++++++++++++++++++++ */function editButton(){$(".insert").hide();$(".update").hide();$(".save").show();$(".cancel").show();$(".other").hide();}//===== 获取右侧主体内容DIV =====///*+++++++++++++++++++++++++++++++++++++ getWrapperBody()++++++++++++++++++++++++++++++++++++ */function getWrapperBody(){var wrapper = $(".statsRow").next().next();var topNav = $(".topNav").next();//正常页的提示位置if(wrapper.attr("class") == "wrapper"){return wrapper;}//弹出也的提示位置else if (topNav.attr("class") == "wrapper"){return topNav;}}//===== 重载提示框体 =====///*+++++++++++++++++++++++++++++++++++++ reLoadMessage()++++++++++++++++++++++++++++++++++++ */function reLoadMessage(){$(".hideit").click(function() {$(this).fadeTo(200, 0.00, function() { //消退200$(this).slideUp(300, function() { // 渐变300$(this).remove(); // 移除});});});}//===== 错误提示语 =====///*+++++++++++++++++++++++++++++++++++++ nWarning(要提示的信息)++++++++++++++++++++++++++++++++++++ */function nWarning(message){var h = "<div class=/"nNote nWarning hideit/">"+"<p><strong>错误: </strong>"+message+"</p>"+"</div>";var wrapper = getWrapperBody();wrapper.PRepend(h);reLoadMessage();}//===== 通知提示语 =====///*+++++++++++++++++++++++++++++++++++++ nWarning(要提示的信息)++++++++++++++++++++++++++++++++++++ */function nInformation(message){var h = "<div class=/"nNote nInformation hideit/">"+"<p><strong>通知: </strong>"+message+"</p>"+"</div>";var wrapper = getWrapperBody();wrapper.prepend(h);reLoadMessage();}//===== 图片预览 =====///*+++++++++++++++++++++++++++++++++++++ upload(this.id)++++++++++++++++++++++++++++++++++++ */function upload(fileId) {var file = document.getElementById(fileId);var img = document.getElementById(fileId+"Pic");if (file.files) {img.src = window.URL.createObjectURL(file.files[0]);}}//===== 检测系统是否超时 =====///*+++++++++++++++++++++++++++++++++++++ isTimeout++++++++++++++++++++++++++++++++++++ */function isTimeout(timeoutTime,loginoutPage){ctionTime = new Date();// 检测时间var openMinutes = openTime.getHours()*60+openTime.getMinutes();// 打开页面的分钟var ctionMinutes = ctionTime.getHours()*60+ctionTime.getMinutes();// 检测时的分钟if( ctionMinutes - openMinutes > timeoutTime){// 如果超时window.location.href = "http://"+loginoutPage;// 注销}}//===== 控制台 =====//function JsLog(data){if(debug&&window.console){window.console.log(data);}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表