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 ...
随机推荐
- bootstrap - typeahead自动补全插件
$('#Sale').typeahead({ ajax: { url: '@Url.Action("../Contract/GetSale")', //timeout: 300, ...
- Debian8修改启动默认运行级别
Two things you need to know: 1) Systemd boots towards the target given by "default.target" ...
- sql server死锁神器
参考文章: http://blogs.msdn.com/b/sqlserverfaq/archive/2013/04/27/an-in-depth-look-at-sql-server-memory- ...
- .Net相关
Lucene 全文搜索 http://lucenenet.apache.org/ Memcached 分布式缓存 http://memcached.org/ selenium UI自动化测试 http ...
- 使用axes函数在matlab绘图中实现图中图的绘制
使用axes函数在matlab绘图中实现图中图的绘制 有时为了对细节进行详细说明,需要在一个较大坐标轴上绘制一个小图来对局部进行放大以阐述结果. 这可以通过调用axes函数实现. 下面通过绘制 y=1 ...
- mysql 根据字段重复 删除 保留一条
delete from TableName where id not in (select minid from (select min(id) as minid from TableName gro ...
- ElasticSearch入门系列(四)分布式初探
序言:ElasticSearch致力于隐藏分布式系统的复杂性,以下的操作都是在底层自动完成的: 将你的文档分区到不同的容器或者分片(shards),他们可以存在于一个或多个节点中 将分片均匀的分配到各 ...
- C++的异常处理之一:throw是个一无是处的东西
看这篇文章学习C++异常处理的基础知识.看完后,还不过瘾,为什么大家在C++代码中都不用Exception?为什么C++11会引入一些变化? 为什么C++ exception handling需要un ...
- ASP.NET配置Ueditor编辑器上传图片路径
1.配置ueditor/editor_config.js文件,将 //图片上传配置区 ,imageUrl:URL+"net/imageUp.ashx" //图片上传提交地址 ,im ...
- 一个Activity掌握Android5.0新控件 (转)
原文地址:http://blog.csdn.net/lavor_zl/article/details/51279386 谷歌在推出Android5.0的同时推出了一些新控件,Android5.0中最常 ...