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"),如果不存在,则返回nullString.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) {//如果不为数字,则返回0if (!/^(-)?\d+(\.\d+)?$/.test(this)) {return 0;} else {if (typeof (fix) != "undefined") { return parseFloat(this).toDecimal(fix); }return parseFloat(this);}}//Number类型加法toAddNumber.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类型减法toSubNumber.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");//结果:SnTeString.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') }}

转载于:https://www.cnblogs.com/sntetwt/p/6492051.html

common.js 2017相关推荐

  1. vue在浏览器端报错:Module not found: Error: Can't resolve 'common/js/util' in 'E:\vue-exercise\sell\src'

    在用vue开发的时候,在浏览器端报错: Module not found: Error: Can't resolve 'common/js/util' in 'E:\vue-exercise\sell ...

  2. 解决element-ui.common.js?5c96:3:Navigation cancelled from “/admin“ to “/users“ with a new navigation.

    当我在写电商管理系统时,点击菜单栏进行路由跳转时,报一个关于路由的错误 element-ui.common.js?5c96:3374 Error: Navigation cancelled from ...

  3. http://open.map.qq.com/c/=/apifiles/2/4/71/mods/common.js,apifiles/2/4/71/mods/map.js 腾讯地图 Vue3 解决方案

    报错信息 http://open.map.qq.com/c/=/apifiles/2/4/71/mods/common.js,apifiles/2/4/71/mods/map.js,apifiles/ ...

  4. 【JS模块】common JS 规范 看这一篇足够了

    为什么会有模块这个说法 我们通常在学习新的东西时,都要问一个问题:为什么需要它,它能干嘛,它解决了什么? 模块往往是语言标准中的一部门,最基本的作用就是隔离命名空间,避免出现命名冲突. 假设: 在a. ...

  5. TS无法找到模块“common.js”的声明文件

    按照百度的新建common.d.ts文件并输入declare module '*.js';  依然会报错common.d.tsis not a module. 正确解决办法是: src下的shims- ...

  6. 封装方法公共文件common.js

    /** * Created by Administrator on 2017/3/24. */ /** * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值 ...

  7. commonjs是什么_第一步:面试官让我解释什么是Common.js和ES6模块化

    前两篇文章中,有小伙伴给我留言说怎么没有模块化相关的知识点,模块化在面试中被问到的概率非常大,但因为前几篇文章篇幅实在太长了些,所以模块化知识点单独这篇文章给大家聊聊. 先说说什么是模块化,就是将独立 ...

  8. common.js 通用方法封装

    /*** 通用方法封装处理** Created by on 2018/9/7*/ (function ($) {var $table = $('#table');$.extend({/*** 表格封装 ...

  9. 前端学习(2134):前端模块化雏形和common.js

最新文章

  1. Zookeeper 典型应用场景介绍
  2. Comperhend the OP-sizeof deeply!
  3. 关于第5周反向传播算法的一些争论与思考
  4. 【Mybatis 之应用篇】 4_动态SQL、缓存
  5. bat脚本 git pull_bat文件方式对git进行操作
  6. Vue 导入文件import、路径@和.的区别
  7. vs 2010 不显示解决方案文件
  8. iOS 应用状态详解
  9. JAVA 反射机制 获得 private 变量
  10. 快手上市,有一批员工平均身家超3200万,但追赶抖音没那么简单
  11. 通达信手机版分时图指标大全_通达信精选指标——挣开眼就买卖版指标详解
  12. DAOS 分布式异步对象存储|事务模型
  13. 巨头倾轧却能强劲生长,青云做对了什么?
  14. Spring Boot 优雅停机
  15. 站长导航系统源码-修复版
  16. 树莓派 Raspberry Pi 安装视频播放软件-omxplayer 并配置全屏播放
  17. 有限元流体模拟matlab仿真
  18. 如何安装Endnote以及如何在word2013中关联endnote
  19. 从程序员到项目经理(5):程序员加油站,不是人人都懂的学习要点
  20. 龙芯3A4000安装Debian10(buster)

热门文章

  1. 深度学习笔记(20) 端到端学习
  2. Android 蓝牙开发——HCI log 分析(十九)
  3. Simulink之功率二极管(整流二极管)
  4. 远程开启3389端口
  5. Linux音频设备驱动_OSS驱动框架(四)————OSS 用户空间编程
  6. C#导入CSV文件处理特殊字符
  7. Java基础1:课程概述
  8. 制作mysql8.0.22 绿色版
  9. P2028 龙兄摘苹果-Stiring-第二类斯特林数
  10. 记一次创维32H3电视安装第三方软件教程