📄 base.js
字号:
/** * 本文件主要放一些常用的js函数 */function go(url) { window.location = href = url; return false;}function traffic(){ for(var i = 0; i < arguments.length; i++) { $.getJSON(arguments[i] + "&t=" + ((new Date).getTime()) + "&=?"); }}function islogin() { return $.cookie('username') == null ? false : true;}function loginDo(func, f) { var fn, flag = f == undefined ? true : false; switch (typeof func) { case 'function' : fn = func break; case 'string' : eval('fn = function(){' + func + '}'); break; default : fn = function(){}; break; } if (islogin()) { fn() } else { if(flag) { //$.cookie('loginedDo',fn.toString()); $.popup.show({url:'/index.php?do=user_account_simpleForm',width:372,height:400,title:'电源网会员登录'}) } else { $.cookie('backurl',location.href,{path: '/', domain: 'dianyuan.com'}); location.href = 'http://www.dianyuan.com/index.php?do=user_account_form'; } }}function loginedRun(fn){ fn = typeof fn == 'function' ? fn : function(){}; if(islogin()){ fn() } else { $.popup.show({ url : 'index.php?do=user_account_simpleForm', width : 372, height : 400, title : '电源网会员登录', flag : 'simple_login' }); }}function checkCheckbox() { var flag = false; $('input[type=checkbox]').each(function(){ if ($(this).attr('checked')) { flag = true; return false; } }); return flag;}function openwinx(url,name,w,h){ window.open(url,name,"top=100,left=400,width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");}function strlen(str) { //中文等两个字符 var len = 0; var a = str.split(""); for (var i=0;i<a.length;i++) { if (a[i].charCodeAt(0)<299) { len++; } else { len+=2; } } return len;}function jsIncAction(url,id){ $("#"+id).html("<img src=/image/ico/loader.gif />"); $("#"+id).load(url+"&rand="+Math.random(), function($data) { //todo } );}function setcookie(cookieName, cookieValue, seconds, path, domain, secure){ var expires = new Date(); expires.setTime(expires.getTime() + seconds * 1000); domain = ''; path = ''; document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');}function getcookie(name){ var cookie_start = document.cookie.indexOf(name); var cookie_end = document.cookie.indexOf(";", cookie_start); return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));}/** loadOption(select, optionData, currValue) | loadOption(select, optionData) * 给select装载option, optionData可以是url,也可以是json, select可以是select的id,也可以是对象。 */function loadOption() { var selectId = arguments[0]; var selectObj = {}; if (typeof (selectId) == 'string') { selectObj = $('#' + selectId); } else { selectObj = $(selectId); } var optionData = arguments[1]; var currValue = ''; if (arguments.length >= 3) { var currValue = arguments[2] + ""; var separator = arguments[3] ? arguments[3] : ","; currValue = currValue.split(separator); } var html = ''; if (typeof (optionData) == 'string') { optionData += '&t=' + (new Date).getTime(); $.get(optionData,'',function(data) { for (var i in data) { html += '<option value="' + i + '"'; html += in_array(i, currValue) ? ' selected' : ''; html += '>' + data[i] + '</option>'; } selectObj.html(html); }, 'json'); } if (typeof (optionData) == 'object') { for (var i in optionData) { html += '<option value="' + i + '"';// html += (i == currValue) ? ' selected' : ''; html += in_array(i, currValue) ? ' selected' : ''; html += '>' + optionData[i] + '</option>'; selectObj.html(html); } }}function in_array(value, arr) { var sign = false; for (var i in arr) { if (value == arr[i]) { sign = true; break; } } return sign;}String.prototype.trim = function() { return this.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)/g, "")};String.prototype.byteLength = function() { return this.replace(/[^\u0000-\u007f]/g, "\u0061\u0061").length};/** * 预装载图片 images可以是单个图片,也可以是数组 */function loadImage(imageSrc) { var imageObj = new Image(); if (typeof (imageSrc) == 'string') { imageObj.src = imageSrc; } if (typeof (imageSrc) == 'object') { //数组 for (i in imageSrc) { imageObj.src = imageSrc[i]; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -