欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

本人自用的global.js庫源碼分享

 更新時(shí)間:2015年02月28日 09:06:27   投稿:junjie  
這篇文章主要介紹了本人自用的global.js庫源碼分享,源碼中包含常用WEB操作,如命名空間、DOM操作、數(shù)據(jù)判斷、Cookie操作等功能,需要的朋友可以參考下
var GLOBAL = {};
GLOBAL.namespace = function(str) {
  var arr = str.split("."), o = GLOBAL,i;
  for (i = (arr[0] = "GLOBAL") ? 1 : 0; i < arr.length; i++) {
    o[arr[i]] = o[arr[i]] || {};
    o = o[arr[i]];
  }
};
//Dom相關(guān)
GLOBAL.namespace("Dom");

GLOBAL.Dom.getNextNode = function (node) {
  node = typeof node == "string" ? document.getElementById(node) : node;
  var nextNode = node.nextSibling;
  if (!nextNode) {
    return null;
  }
  if (!document.all) {
    while (true) {
      if (nextNode.nodeType == 1) {
        break;

      } else {
        if (nextNode.nextSibling) {
          nextNode = nextNode.nextSibling;
        } else {
          break;
        }
      }
    }
    return nextNode;
  }
}

GLOBAL.Dom.setOpacity = function(node, level) {
  node = typeof node == "string" ? document.getElementById(node) : node;
  if (document.all) {
    node.style.filter = 'alpha(opacity=' + level + ')';
  } else {
    node.style.opacity = level / 100;
  }
};

GLOBAL.Dom.getElementsByClassName = function (str, root, tag) {
  if (root) {
    root = typeof root == "string" ? document.getElementById(root) : root;
  } else {
    root = document.body;
  }
  tag = tag || "*";
  var els = root.getElementsByTagName(tag), arr = [];
  for (var i = 0, n = els.length; i < n; i++) {
    for (var j = 0, k = els[i].className.split(" "), l = k.length; j < l; j++) {
      if (k[j] == str) {
        arr.push(els[i]);
        break;
      }
    }
  }
  return arr;
}
GLOBAL.namespace("Event");
GLOBAL.Event.stopPropagation = function(e) {
  e = window.event || e;
  if (document.all) {
    e.cancelBubble = true;
  } else {
    e.stopPropagation();
  }
};
GLOBAL.Event.getEventTarget = function(e) {
  e = window.event || e;
  return e.srcElement || e.target;
};

GLOBAL.Event.on = function(node, eventType, handler) {
  node = typeof node == "string" ? document.getElementById(node) : node;
  if (document.all) {
    node.attachEvent("on" + eventType, handler);
  } else {
    node.addEventListener(eventType, handler, false);
  }
};

//Lang相關(guān)
GLOBAL.namespace("Lang");
GLOBAL.Lang.trim = function(ostr) {
  return ostr.replace(/^\s+|\s+$/g, "");
};

GLOBAL.Lang.isNumber = function(s) {
  return !isNaN(s);
};

function isString(s) {
  return typeof s === "string";
}



function isBoolean(s) {
  return typeof s === "boolean";
}

function isFunction(s) {
  return typeof s === "function";
}

function isNull(s) {
  return s === null;
}

function isUndefined(s) {
  return typeof s === "undefined";
}

function isEmpty(s) {
  return /^\s*$/.test(s);
}

function isArray(s) {
  return s instanceof Array;
}

GLOBAL.Dom.get = function (node) {
  node = typeof node === "string" ? document.getElementById(node) : node;
  return node;
}

function $(node) {
  node = typeof node == "string" ? document.getElementById(node) : node;
  return node;
}


GLOBAL.Lang.extend = function(subClass, superClass) {
  var F = function() {
  };
  F.prototype = superClass.prototype;
  subClass.prototype = new F();
  subClass.prototype.constructor = subClass;
  subClass.superClass = subClass.prototype;
  if (superClass.prototype.constructor == Object.prototype.constructor) {
    superClass.prototype.constructor = superClass;
  }
};

GLOBAL.namespace("Cookie");
GLOBAL.Cookie = {
  read: function (name) {
    var cookieStr = ";" + document.cookie + ";";
    var index = cookieStr.indexOf(";" + name + "=");
    if (index != -1) {
      var s = cookieStr.substring(index + name.length + 3, cookieStr.length);
      return unescape(s.substring(0, s.indexOf(";")));
    } else {
      return null;
    }
  },
  set: function (name, value, expires) {
    var expDays = expires * 24 * 60 * 60 * 1000;
    var expDate = new Date();
    expDate.setTime(expDate.getTime() + expDays);
    var expString = expires ? ";expires=" + expDate.toGMTString() : "";
    var pathString = ";path=/";
    document.cookie = name + "=" + escape(value) + expString + pathString;
  },
  del: function (name, value, expires) {
    var exp = new Date(new Date().getTime() - 1);
    var s = this.read(name);
    if (s != null) {
      document.cookie = name + "=" + s + ";expires=" + exp.toGMTString() + ";path=/";
    }
  }
};

相關(guān)文章

  • 基于JS實(shí)現(xiàn)頁面懸浮框的實(shí)例代碼

    基于JS實(shí)現(xiàn)頁面懸浮框的實(shí)例代碼

    這篇文章主要介紹了基于JS實(shí)現(xiàn)頁面懸浮框的實(shí)例代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • 微信小程序自定義時(shí)間段picker選擇器

    微信小程序自定義時(shí)間段picker選擇器

    這篇文章主要為大家詳細(xì)介紹了微信小程序自定義時(shí)間段picker選擇器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-07-07
  • JavaScript中繼承原理與用法實(shí)例入門

    JavaScript中繼承原理與用法實(shí)例入門

    這篇文章主要介紹了JavaScript中繼承原理與用法,結(jié)合實(shí)例形式分析了JavaScript中繼承的基本概念、原理、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2020-05-05
  • JavaScript根據(jù)json生成html表格的示例代碼

    JavaScript根據(jù)json生成html表格的示例代碼

    這篇文章主要介紹了JavaScript根據(jù)json生成html表格的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • js中this用法實(shí)例詳解

    js中this用法實(shí)例詳解

    這篇文章主要介紹了js中this用法,實(shí)例分析了this指向windows、指向?qū)ο蠹案淖僼his指向的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • JavaScrip簡(jiǎn)單數(shù)據(jù)類型隱式轉(zhuǎn)換的實(shí)現(xiàn)

    JavaScrip簡(jiǎn)單數(shù)據(jù)類型隱式轉(zhuǎn)換的實(shí)現(xiàn)

    本文主要介紹了JavaScrip簡(jiǎn)單數(shù)據(jù)類型隱式轉(zhuǎn)換的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • 微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)

    微信小程序?qū)崿F(xiàn)倒計(jì)時(shí)

    這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 微信小程序中視頻的顯示與隱藏功能

    微信小程序中視頻的顯示與隱藏功能

    這篇文章主要介紹了微信小程序中視頻的顯示與隱藏,思路大概是定義一個(gè)標(biāo)記變量,控制視頻的播放與暫停,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-10-10
  • bootstrapValidator自定驗(yàn)證方法寫法

    bootstrapValidator自定驗(yàn)證方法寫法

    這篇文章主要為大家詳細(xì)介紹了bootstrapValidator自定驗(yàn)證方法寫法,研究bootstrapValidator驗(yàn)證,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • js字符串中空格和換行符(\r,\s,\n,\r\n)淺析

    js字符串中空格和換行符(\r,\s,\n,\r\n)淺析

    我們?cè)谑褂米址畷r(shí)經(jīng)常會(huì)遇到換行問題,下面這篇文章主要給大家介紹了關(guān)于js字符串中空格和換行符(\r,\s,\n,\r\n)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07

最新評(píng)論