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. 【Devops】【docker】【CI/CD】jenkins 清除工作空间报错Error: Wipe Out Workspace blocked by SCM

    jenkins 清除工作空间报错 错误如下: Error: Wipe Out Workspace blocked by SCM 解决方法: 进入jenkins服务器,进入workspace,手动rm ...

  2. WordPress主题开发:优化标题

    页面使用: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  3. React中的的JSX

    什么是JSX? JSX是JavaScript XML的缩写,其本质是js,表现形式类似于XML,与js区别在于可直接在里面编写html标签. 怎么使用JSX? 语法规则: JSX 的基本语法规则:HT ...

  4. WordPress主题开发:循环代码

    have_posts() 有没有文章信息 if...else <?php if( have_posts() ) : while( have_posts() ) : the_post(); ?&g ...

  5. JS --- 三目运算符

    1.什么是三目运算:(布尔表达式 ? 值0:值1;) 5>3?alert('5大'):alert('3大'); 即    if(5>3){alert('5大')}else{alert('3 ...

  6. 亿万第一至二季/全集Billions迅雷下载

    英文全名Billions,第1季(2016)Showtime. 本季看点:<亿万>讲述了纽约市政治与经济领域.关于金钱的一场较量.故事主要描述两个华尔街重量级人物之间的战争.精明.强硬的检 ...

  7. Java中CAS详解

    在JDK 5之前Java语言是靠synchronized关键字保证同步的,这会导致有锁 锁机制存在以下问题: (1)在多线程竞争下,加锁.释放锁会导致比较多的上下文切换和调度延时,引起性能问题. (2 ...

  8. 《数据挖掘:R语言实战》

    <数据挖掘:R语言实战> 基本信息 作者: 黄文    王正林 丛书名: 大数据时代的R语言 出版社:电子工业出版社 ISBN:9787121231223 上架时间:2014-6-6 出版 ...

  9. java转义符和正则表达式转义符

    举例来说,连续相同的3位数字的正则表达式的标准语法是: ([\d])\1{2} 但是如果在java代码中这么写,就会出现语法错误,如下: String regEx = "([\d])\1{2 ...

  10. Orchard模块开发全接触6:自定义用户注册

    我们都知道 Orchard 的用户注册相当简单,现在,我们需要一个自定义的用户注册,现在,开始吧. 一:定义实体 Models/CustomerPartRecord.cs: public class ...