common.js 2017
String.IsNullOrEmpty = function (v) {
return !(typeof (v) === "string" && v.length != 0);
};
String.prototype.Trim = function (isall) {
if (isall) {
//清除所有空格
return this.replace(/\s/g, "");
}
//清除两边空格
return this.replace(/^\s+|\s+$/g, "")
};
//清除开始空格
String.prototype.TrimStart = function (v) {
if ($String.IsNullOrEmpty(v)) {
v = "\\s";
};
var re = new RegExp("^" + v + "*", "ig");
return this.replace(re, "");
};
//清除结束空格
String.prototype.TrimEnd = function (v) {
if ($String.IsNullOrEmpty(c)) {
c = "\\s";
};
var re = new RegExp(c + "*$", "ig");
return v.replace(re, "");
};
//获取url参数,调用:window.location.search.Request("test"),如果不存在,则返回null
String.prototype.Request = function (para) {
var reg = new RegExp("(^|&)" + para + "=([^&]*)(&|$)");
var r = this.substr(this.indexOf("\?") + 1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
//四舍五入保留二位小数
Number.prototype.ToDecimal = function (dec) {
//如果是整数,则返回
var num = this.toString();
var idx = num.indexOf(".");
if (idx < 0) return this;
var n = num.length - idx - 1;
//如果是小数,则返回保留小数
if (dec < n) {
var e = Math.pow(10, dec);
return Math.round(this * e) / e;
} else {
return this;
}
}
//字符转换为数字
String.prototype.ToNumber = function (fix) {
//如果不为数字,则返回0
if (!/^(-)?\d+(\.\d+)?$/.test(this)) {
return 0;
} else {
if (typeof (fix) != "undefined") { return parseFloat(this).toDecimal(fix); }
return parseFloat(this);
}
}
//Number类型加法toAdd
Number.prototype.ToAdd = function () {
var _this = this;
var len = arguments.length;
if (len == 0) { return _this; }
for (i = 0 ; i < len; i++) {
var arg = arguments[i].toString().toNumber();
_this += arg;
}
return _this.toDecimal(2);
}
//Number类型减法toSub
Number.prototype.ToSub = function () {
var _this = this;
var len = arguments.length;
if (len == 0) { return _this; }
for (i = 0 ; i < len; i++) {
var arg = arguments[i].toString().toNumber();
_this -= arg;
}
return _this.toDecimal(2);
}
//字符格式化:String.format("S{0}T{1}","n","e");//结果:SnTe
String.Format = function () {
var c = arguments[0];
for (var a = 0; a < arguments.length - 1; a++) {
var b = new RegExp("\\{" + a + "\\}", "gm");
c = c.replace(b, arguments[a + 1])
}
return c
};
/*
*字符填充类(长度小于,字符填充)
*调用实例
*var s = "471812366";
*s.leftpad(10, '00'); //结果:00471812366
*s.rightpad(10, '00'); //结果:47181236600
*左填充
*/
String.prototype.LeftPad = function (b, f) {
if (arguments.length == 1) {
f = "0"
}
var e = new StringBuffer();
for (var d = 0,
a = b - this.length; d < a; d++) {
e.append(f)
}
e.append(this);
return e.toString()
};
//右填充
String.prototype.RightPad = function (b, f) {
if (arguments.length == 1) {
f = "0"
}
var e = new StringBuffer();
e.append(this);
for (var d = 0,
a = b - this.length; d < a; d++) {
e.append(f)
}
return e.toString()
};
//加载JS文件
//调用:window.using('/scripts/test.js');
window.using = function (jsPath, callback) {
$.getScript(jsPath, function () {
if (typeof callback == "function") {
callback();
}
});
}
//自定义命名空间
//定义:namespace("Utils")["Test"] = {}
//调用:if (Utils.Error.hasOwnProperty('test')) { Utils.Error['test'](); }
window.namespace = function (a) {
var ro = window;
if (!(typeof (a) === "string" && a.length != 0)) {
return ro;
}
var co = ro;
var nsp = a.split(".");
for (var i = 0; i < nsp.length; i++) {
var cp = nsp[i];
if (!ro[cp]) {
ro[cp] = {};
};
co = ro = ro[cp];
};
return co;
};
/*====================================
创建Cookie:Micro.Cookie("名称", "值", { expires: 7 }, path: '/' );
expires:如果省略,将在用户退出浏览器时被删除。
path:的默认值为网页所拥有的域名
添加Cookie:Micro.Cookie("名称", "值");
设置有效时间(天):Micro.Cookie("名称", "值", { expires: 7 });
设置有效路径(天):Micro.Cookie("名称", "值", { expires: 7 }, path: '/' );
读取Cookie: Micro.Cookie("名称"});,如果cookie不存在则返回null
删除Cookie:Micro.Cookie("名称", null); ,删除用null作为cookie的值即可
*作者:杨秀徐
====================================*/
namespace("Micro")["Cookie"] = function (name, value, options) {
if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].Trim(true);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
//错误处理方法
namespace("Micro")["Error"] = {
a: function () { alert('a') },
b: function () { alert('b') },
c: function () { alert('c') }
}
//常规处理方法
namespace("Micro")["Utils"] = {
isMobile: function () {
var userAgent = navigator.userAgent.toLowerCase();
var isIpad = userAgent.match(/ipad/i) == "ipad";
var isIphoneOs = userAgent.match(/iphone os/i) == "iphone os";
var isMidp = userAgent.match(/midp/i) == "midp";
var isUc7 = userAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
var isUc = userAgent.match(/ucweb/i) == "ucweb";
var isAndroid = userAgent.match(/android/i) == "android";
var isCE = userAgent.match(/windows ce/i) == "windows ce";
var isWM = userAgent.match(/windows mobile/i) == "windows mobile";
if (isIpad || isIphoneOs || isMidp || isUc7 || isUc || isAndroid || isCE || isWM) {
return true;
} else {
return false;
}
},
b: function () { alert('b') },
c: function () { alert('c') }
}
common.js 2017的更多相关文章
- (六)Net Core项目使用Controller之一 c# log4net 不输出日志 .NET Standard库引用导致的FileNotFoundException探究 获取json串里的某个属性值 common.js 如何调用common.js js 筛选数据 Join 具体用法
(六)Net Core项目使用Controller之一 一.简介 1.当前最流行的开发模式是前后端分离,Controller作为后端的核心输出,是开发人员使用最多的技术点. 2.个人所在的团队已经选择 ...
- angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)
common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...
- 封装自己的Common.js工具库
Code/** * Created by LT on 2013/6/16. * Common.js * 对原生JS对象的扩展 * Object.Array.String.Date.Ajax.Cooki ...
- vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined
我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...
- 常用js方法整理common.js
项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...
- 项目中常用js方法整理common.js
抽空把项目中常用js方法整理成了common.js,都是网上搜集而来的,大家一起分享吧. var h = {}; h.get = function (url, data, ok, error) { $ ...
- 模块化规范Common.js,AMD,CMD
随着网站规模的不断扩大,嵌入网页中的javascript代码越来越大,开发过程中存在大量问题,如:协同开发,代码复用,大量文件引入,命名冲突,文件依赖. 模块化编程称为迫切的需求. 所谓的模块,就是实 ...
- 如何调用common.js
第一步 页面需要引用此js 第二步 var loginJs = { //登录 goLogin: function () { var _userinfo = { name: "夏小沫" ...
- visual studio 2005提示脚本错误 /VC/VCWizards/2052/Common.js
今天在做OCX添加接口的时候,莫名其妙的遇到visual studio 2005提示脚本错误,/VC/VCWizards/2052/Common.js. 网上找了很多资料,多数介绍修改注册表“vs20 ...
随机推荐
- 解决Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COER
今天在用java与mysql数据库时发现Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COER ...
- Ubuntu上的Hadoop安装教程
Install Hadoop 2.2.0 on Ubuntu Linux 13.04 (Single-Node Cluster) This tutorial explains how to insta ...
- 搭建《深入Linux内核架构》的Linux环境
作者 彭东林 pengdonglin137@163.com 软件 Host: Ubuntu14.04 64 Qemu 2.8.0 Linux 2.6.24 busybox 1.24.2 gcc 4.4 ...
- 使用Axure RP原型设计实践05,了解公式
本篇体验公式的使用,一般出现值的时候就可以使用公式,公式可以使用全局变量也可以使用局部变量,在Axure中使用公司有一定的语法. 先创建2个全局变量. 向页面中拖入Rectangle部件,给它的OnC ...
- 使用Axure RP原型设计实践02,自定义部件以及熟悉与部件相关面板
本篇体验在Axure中自定义部件,并熟悉Widget Interations and Notes面板,Widget Properties and Style面板,Widget Manager面板. 在 ...
- 利用mvn deploy命令上传包(转)
本文转自https://blog.csdn.net/chenaini119/article/details/52764543 mvn安装 下载maven的bin,在apache官方网站可以下载. ht ...
- eclipse使用profile完成不同环境的maven打包功能
原文:https://blog.csdn.net/duan9421/article/details/79086335 我们在日常开发工作中通常会根据不同的项目运行环境,添加不同的配置文件,例如 开发环 ...
- 【转】IntelliJ IDEA关联SVN
http://blog.csdn.net/xdd19910505/article/details/52756417 问题描述: IntelliJ IDEA安装之后,使用SVN进行提交或更新以及检出代码 ...
- 实用ExtJS教程100例-009:ExtJS Form无刷新文件上传
文件上传在Web程序开发中必不可少,ExtJS Form中有一个filefield字段,用来选择文件并上传.今天我们来演示一下如何通过filefield实现ExtJS Form无刷新的文件上传. 首先 ...
- COPY ORCHARD GET 404: System.UnauthorizedAccessException: mappings.bin的访问被拒绝
COPY ORCHARD 得到 404 错误,结果翻看Logs,得到的错误是: 014-07-31 17:36:46,217 [16] Orchard.Environment.DefaultOrcha ...