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 ...
随机推荐
- Node基础:url查询参数解析之querystring
模块概述 在nodejs中,提供了querystring这个模块,用来做url查询参数的解析,使用非常简单. 模块总共有四个方法,绝大部分时,我们只会用到 .parse(). .stringify() ...
- 数学符号“s.t.”的意义
在优化问题的求解中,如线性规划.非线性规划问题等,经常会遇到数学符号“s.t.”,它的意思是什么呢? “s.t.”,指 subject to,受限制于.... 例如: 目标函数:min {x+2} 约 ...
- pageEncoding与contentType属性
1图例分析 由图中可以看出,这个两个属性没有任何关系. 把这两个设置成不同的编码格式对中文显示不会产生任何影响 2.原因分析 pageEncoding规定了以什么编码方式存储和读取,使两者保持一致性, ...
- easyui添加生成tab和子页面jsp
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>& ...
- 初探psutil
系统性能信息模块psutil 1,psutil简介 psutil是一个跨平台能够轻松获取系统的进程和系统利用率,主要应用在系统监控,分析和限制系统资源以及进程管理.它实现了很多系统管理的命令,如ps, ...
- Mustache 使用总结
前言: 在分析 jeesite 项目的时候,看到了 Mustache,于是查了下 正文: 1.Mustache 概述 Mustache 是基于 JavaScript 实现的模板引擎,即用来 渲染前台页 ...
- C#-WinForm-对话框控件
对话框控件 设置点击按钮弹出对话框控件 1.colorDialog - 颜色对话框 接收确定返回的信息 ============================================ ...
- 网络爬虫2--PHP/CURL库(client URL Request Library)
PHP/CURL库功能 多种传输协议.CURL(client URL Request Library),含义是“客户端URL请求库”. 不像上一篇所用的PHP内置网络函数,PHP/CURL支持多种 ...
- 1.python算法之汉诺塔
代码如下: #!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: 汉诺塔.py @t ...
- 关于IOS时间日历的一些注意事项 NSDateFormatter
1.时间或者日期格式化的格式化,在真机上运行的是hi,必须指定是在哪个区域的,不然在真机无法显示 // 1.日期格式化 NSDateFormatter *fmt = [[NSDateFormatter ...