global--命名空间的使用(一些零散的js方法)
var GLOBAL = {};
GLOBAL.namespace = function (str) {
var arr = str.split('.'), o = GLOBAL;
for (var i = (arr[0] == 'GLOBAL') ? 1 : 0; i < arr.length; i++) {
o[arr[i]] = o[arr[i]] || {};
o = o[arr[i]];
}
}
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.get = function (node) {
node = typeof node == 'string' ? document.getElementById(node) : node;
return node;
}
GLOBAL.Dom.getElementsByClassName = function (str, root, tag) {
if (root) {
root = typeof root == 'string' ? document.getElementById(root) : root;
} else {
root = document.body;
}
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.Dom.addClass = function (node,str) {
if (!new RegExp("(^|\\s+)" + str).test(node.className)) {
node.className = node.className + " " + str;
}
}
GLOBAL.Dom.hasClass = function (name,type) {
var r = [];
var re = new RegExp("(^|\\s)" + name + "(\\s|$)");
var e = document.getElementsByTagName(type || "*");
for (var j = 0; j < e.length; j++) {
if (re.test(e[j])) {
r.push(e[j]);
}
}
return r;
}
GLOBAL.Dom.removeClass = function (node,str) {
node.className=node.className.replace(new RegExp("(^|\\s+)"+str),"");
}
GLOBAL.namespace('Event');
GLOBAL.Event.getEventTarget = function (e) {
e = window.event || e;
return e.srcElement || e.target;
}
GLOBAL.Event.stopPropagation = function (e) {
e = e.window || e;
if (document.all) {
e.cancelBubble = true;
} else {
e.stopPropagation();
}
}
GLOBAL.Event.on = function (node, eventType, handler,scope) {
node = typeof node == 'string' ? document.getElementById(node) : node;
if (document.all) {
node.attachEvent('on' + eventType, function () {
handler.apply(scope, arguments);
});
} else {
node.addEventListener(eventType, function () {
handler.apply(scope, arguments);
}, false);
}
}
GLOBAL.namespace('Lang');
GLOBAL.Lang.trim = function (ostr) {
return ostr.replace(/^\s+|s+$/g, "");
}
GLOBAL.Lang.isNumber = function (s) {
return !isNaN(s);
}
GLOBAL.Lang.isString = function (s) {
return typeof s === 'string';
}
GLOBAL.Lang.isBoolean = function (s) {
return typeof s === 'boolean';
}
GLOBAL.Lang.isFunction = function (s) {
return typeof s === 'function';
}
GLOBAL.Lang.isNull = function (s) {
return s === null;
}
GLOBAL.Lang.isUndefined = function (s) {
return typeof s === 'undefined';
}
GLOBAL.Lang.isEmpty = function (s) {
return /^\s$/.test(s);
}
GLOBAL.Lang.isArray = function (s) {
return s instanceof Array;
}
GLOBAL.Lang.extend = function (subClass, superClass) {
var F = function () { };
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
subClass.superClass = superClass.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 () {
var exp = new Date(new Date().getTime() - 1);
var s = this.read(name);
if (s!=null) {
document.cookie = name + "=" + s + ";expires=" + exp.toGMTString() + ";path=/";
}
}
};
global--命名空间的使用(一些零散的js方法)的更多相关文章
- jQuery事件命名空间多事件绑定自定义事件js 命名空间 javascript命名空间
http://blog.csdn.net/pigpigpig4587/article/details/24727791 jQuery事件命名空间 jQuery支持事件命名空间,以方便事件管理.例如,在 ...
- 【问题】Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数
[问题]Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数. [解决]直接对变量加引号,如: <button onclick="deleteProduct('@ ...
- 解决webkit浏览器中js方法中使用window.event提示未定义的问题
这实际上是一个浏览器兼容性问题,根源百度中一大堆,简要说就是ie中event对象是全局变量,所以哪里都能使用到,但是webkit内核的浏览器中却不存在这个全局变量event,而是以一个隐式的局部变量的 ...
- ASP.Net 在Update Panel局部刷新后 重新绑定JS方法
我们知道Asp.Net中的Update Panel可以完成页面的局部刷新(实质上是Ajax),但是局部刷新完后,此区域的控件上所绑定的JS方法就会失效,因为我们用如下方法来重新绑定. var prm ...
- JS调用OC方法并传值,OC调用JS方法并传值////////////////////////zz
iOS开发-基于原生JS与OC方法互相调用并传值(附HTML代码) 最近项目里面有有个商品活动界面,要与web端传值,将用户在网页点击的商品id 传给客户端,也就是js交互,其实再说明白一点 ...
- 常用js方法
function dateGetter(name, size, offset, trim) { offset = offset || 0; return function (date) { var v ...
- 与考试相关的JS方法
var IsChange = 0;var ensure = 0;var timeCounter = (function () {//考试剩余时间 倒计时 var int; //var total = ...
- Java使用正则表达式取网页中的一段内容(以取Js方法为例)
关于正则表达式: 表1.常用的元字符 代码 说明 . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配字符串 ...
- 我的前端架构之二--统一扩展Js方法
我的前端架构汇总 MyJs_Core.js 这是一个核心的Js文件,它扩展了原生的Js方法.如下: Array对象: 1) indexOf 2) max 3) min 4) removeAt 5) i ...
随机推荐
- Android Stduio统计项目的代码行数
android studio统计项目的代码行数的步骤如下: 1)按住Ctrl+Shift+A,在弹出的框输入‘find’,然后选择Find in Path.(或者使用快捷键Ctrl+Shift+F) ...
- spring MVC学习笔记
为开发团队选择一款优秀的MVC框架是件难事儿,在众多可行的方案中决择需要很高的经验和水平.你的一个决定会影响团队未来的几年.要考虑方面太多: 1.简单易用,以提高开发效率.使小部分的精力在框架上,大部 ...
- Rest API 开发 学习笔记(转)
Rest API 开发 学习笔记 概述 REST 从资源的角度来观察整个网络,分布在各处的资源由URI确定,而客户端的应用通过URI来获取资源的表示方式.获得这些表徵致使这些应用程序转变了其状态.随着 ...
- android 颜色对照
<table><tbody> <tr> <td bgcolor="#ffffff" width="30" height ...
- python基础-编码_if条件判断
一.第一句Python代码 在 /home/dev/ 目录下创建 hello.py 文件,内容如下: [root@python-3 scripts]# cat hello.py #!/usr/bin/ ...
- 十天冲刺---Day3
站立式会议 站立式会议内容总结: git上Issues新增内容: 燃尽图 照片 组长情绪爆炸是很可怕的事情.这里自责一下. 进度缓慢是一件非常头疼的事情.还有每个人的时间都很紧张,除了学习,还有各种工 ...
- Kernel Methods (3) Kernel Linear Regression
Linear Regression 线性回归应该算得上是最简单的一种机器学习算法了吧. 它的问题定义为: 给定训练数据集\(D\), 由\(m\)个二元组\(x_i, y_i\)组成, 其中: \(x ...
- Cannot change version of project facet Dynamic Web Module to 3.1
最近项目一直报错,看的极度的不爽,于是找了很长时间的解决方案. 先说一下环境Spring + SpringMVC + MAVEN + jdk 1.8 + servlet 3.1 由于是web 项目,这 ...
- 浏览器XMLHttpRequest案例
/* Cross-Browser XMLHttpRequest v1.2 ================================= Emulate Gecko 'XMLHttpRequest ...
- d3-画雷达图-圆形弧线
本文转载 终极效果 源码 index.html <!DOCTYPE html> <html> <head> <meta http-equiv="Co ...