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的更多相关文章

  1. (六)Net Core项目使用Controller之一 c# log4net 不输出日志 .NET Standard库引用导致的FileNotFoundException探究 获取json串里的某个属性值 common.js 如何调用common.js js 筛选数据 Join 具体用法

    (六)Net Core项目使用Controller之一 一.简介 1.当前最流行的开发模式是前后端分离,Controller作为后端的核心输出,是开发人员使用最多的技术点. 2.个人所在的团队已经选择 ...

  2. angularjs 1 开发简单案例(包含common.js,service.js,controller.js,page)

    common.js var app = angular.module('app', ['ngFileUpload']) .factory('SV_Common', function ($http) { ...

  3. 封装自己的Common.js工具库

    Code/** * Created by LT on 2013/6/16. * Common.js * 对原生JS对象的扩展 * Object.Array.String.Date.Ajax.Cooki ...

  4. vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined

    我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...

  5. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

  6. 项目中常用js方法整理common.js

    抽空把项目中常用js方法整理成了common.js,都是网上搜集而来的,大家一起分享吧. var h = {}; h.get = function (url, data, ok, error) { $ ...

  7. 模块化规范Common.js,AMD,CMD

    随着网站规模的不断扩大,嵌入网页中的javascript代码越来越大,开发过程中存在大量问题,如:协同开发,代码复用,大量文件引入,命名冲突,文件依赖. 模块化编程称为迫切的需求. 所谓的模块,就是实 ...

  8. 如何调用common.js

    第一步 页面需要引用此js 第二步 var loginJs = { //登录 goLogin: function () { var _userinfo = { name: "夏小沫" ...

  9. visual studio 2005提示脚本错误 /VC/VCWizards/2052/Common.js

    今天在做OCX添加接口的时候,莫名其妙的遇到visual studio 2005提示脚本错误,/VC/VCWizards/2052/Common.js. 网上找了很多资料,多数介绍修改注册表“vs20 ...

随机推荐

  1. mysql大文本数据类型的使用需要考虑实际情况

    mysql数据类型简介(http://news.newhua.com/news1/program_database/2008/618/08618103911CD92HJ6CKI2I9I0AH5CGK1 ...

  2. C#编程(六十七)----------LINQ提供程序

    原文链接:http://blog.csdn.net/shanyongxu/article/details/47257511 LINQ提供程序 .NET3.5包含了几个LINQ提供程序. LINQ提供程 ...

  3. 高通与MTK瓜分天下?手机处理器品牌分析

    http://mobile.pconline.com.cn/337/3379352.html [PConline 杂谈]如果你向朋友请教买一台怎样的台式机或者笔记本的话,很多时候那朋友会根据你对电脑的 ...

  4. hbase经常使用的shell命令样例

    1.hbase shell    进入hbase [hadoop@mdw ~]$ hbase shell HBase Shell; enter 'help<RETURN>' for lis ...

  5. Android中的输入法

    提起输入法我就想到了Edittext,输入法可以自动根据inputType来改变键盘的布局,在支付钱包中还特别隐藏的系统自带的输入法,直接让用户用软件自己的输入法,提高了安全性.所以,我们应该对输入法 ...

  6. Java多线程知识-Callable和Future

    Callable和Future出现的原因 创建线程的2种方式,一种是直接继承Thread,另外一种就是实现Runnable接口. 这2种方式都有一个缺陷就是:在执行完任务之后无法获取执行结果. 如果需 ...

  7. 组件化 得到 DDComponent JIMU 模块 插件 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  8. sharding-jdbc之——分库分表实例

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/79368021 一.概述 之前,我们介绍了利用Mycat进行分库分表操作,Mycat ...

  9. Jsonp 关键字详解及json和jsonp的区别,ajax和jsonp的区别

    为什么要用jsonp? 相信大家对跨域一定不陌生,对同源策略也同样熟悉.什么,你没听过?没关系,既然是深入浅出,那就从头说起. 假如我写了个index页面,页面里有个请求,请求的是一个json数据(不 ...

  10. 【API规范】OpenAPI规范

    OpenAPI规范 openAPI 3.0_百度搜索 OpenAPI Specification 2.0 - CSDN博客 APP相关_API 列表_OpenAPI 2.0_开发指南_移动推送-阿里云 ...