01.function $() {
02. var elements = [];
03. for (var i = 0; i < arguments.length; i++) {
04. var element = arguments[i];
05. if (typeof element == 'string')
06. element = document.getElementById(element);
07. if (arguments.length == 1)
08. return element;
09. elements.push(element);
10. }
11. return elements;
12.}
01.function setStyle(el,prop,value){
02. if(prop == "opacity" && !+"\v1"){
03. //IE7 bug:filter 滤镜要求 hasLayout=true 方可执行(否则没有效果)
04. if (!el.currentStyle || !el.currentStyle.hasLayout) el.style.zoom = 1;
05. prop = "filter";
06. if(!!window.XDomainRequest){
07. value ="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity="+value*100+")";
08. }else{
09. value ="alpha(opacity="+value*100+")"
10. }
11. }
12. el.style.cssText += ';' + (prop+":"+value);
13. }
14. function getStyle(el, style){
15. if(!+"\v1"){
16. style = style.replace(/\-(\w)/g, function(all, letter){
17. return letter.toUpperCase();
18. });
19. return el.currentStyle[style];
20. }else{
21. return document.defaultView.getComputedStyle(el, null).getPropertyValue(style)
22. }
23. }
01.function getCookie( name ) {
02. var start = document.cookie.indexOf( name + "=" );
03. var len = start + name.length + 1;
04. if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
05. return null;
06. }
07. if ( start == -1 ) return null;
08. var end = document.cookie.indexOf( ';', len );
09. if ( end == -1 ) end = document.cookie.length;
10. return unescape( document.cookie.substring( len, end ) );
11.}
12.function setCookie( name, value, expires, path, domain, secure ) {
13. var today = new Date();
14. today.setTime( today.getTime() );
15. if ( expires ) {
16. expires = expires * 1000 * 60 * 60 * 24;
17. }
18. var expires_date = new Date( today.getTime() + (expires) );
19. document.cookie = name+'='+escape( value ) +
20. ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
21. ( ( path ) ? ';path=' + path : '' ) +
22. ( ( domain ) ? ';domain=' + domain : '' ) +
23. ( ( secure ) ? ';secure' : '' );
24.}
25.function deleteCookie( name, path, domain ) {
26. if ( getCookie( name ) ) document.cookie = name + '=' +
27. ( ( path ) ? ';path=' + path : '') +
28. ( ( domain ) ? ';domain=' + domain : '' ) +
29. ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
30.}
1.Array.prototype.inArray = function (value) {
2. for (var i=0,l = this.length ; i <l ; i++) {
3. if (this[i] === value) {
4. return true;
5. }
6. }
7. return false;
8.};
1.function insertAfter(parent, node, referenceNode) {
2. parent.insertBefore(node, referenceNode.nextSibling);
3.}
01.function toggle(obj) {
02. var el = document.getElementById(obj);
03. if ( el.style.display != 'none' ) {
04. el.style.display = 'none';
05. }
06. else {
07. el.style.display = '';
08. }
09.}
01.var getElementsByClassName = function (searchClass, node,tag) {
02. if(document.getElementsByClassName){
03. return document.getElementsByClassName(searchClass)
04. }else{
05. node = node || document;
06. tag = tag || "*";
07. var classes = searchClass.split(" "),
08. elements = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag),
09. patterns = [],
10. returnElements = [],
11. current,
12. match;
13. var i = classes.length;
14. while(--i >= 0){
15. patterns.push(new RegExp("(^|\\s)" + classes[i] + "(\\s|$)"));
16. }
17. var j = elements.length;
18. while(--j >= 0){
19. current = elements[j];
20. match = false;
21. for(var k=0, kl=patterns.length; k<kl; k++){
22. match = patterns[k].test(current.className);
23. if (!match) break;
24. }
25. if (match) returnElements.push(current);
26. }
27. return returnElements;
28. }
29.}
01.var addLoadEvent = function(fn) {
02. var oldonload = window.onload;
03. if (typeof window.onload != 'function') {
04. window.onload = fn;
05. }else {
06. window.onload = function() {
07. oldonload();
08. fn();
09. }
10. }
11.}
01.function addEvent(elm, evType, fn, useCapture) {
02. if (elm.addEventListener) {
03. elm.addEventListener(evType, fn, useCapture);//DOM2.0
04. return true;
05. }
06. else if (elm.attachEvent) {
07. var r = elm.attachEvent('on' + evType, fn);//IE5+
08. return r;
09. }
10. else {
11. elm['on' + evType] = fn;//DOM 0
12. }
13.}
01.function addEvent(elm, evType, fn, useCapture) {
02. if (elm.addEventListener) {
03. elm.addEventListener(evType, fn, useCapture);//DOM2.0
04. return true;
05. }
06. else if (elm.attachEvent) {
07. var r = elm.attachEvent('on' + evType, fn);//IE5+
08. return r;
09. }
10. else {
11. elm['on' + evType] = fn;//DOM 0
12. }
13.}
01.//addEvent/removeEvent written by Dean Edwards, 2005
02.//with input from Tino Zijdel
03.//http://dean.edwards.name/weblog/2005/10/add-event/
04.function addEvent(element, type, handler) {
05. //为每一个事件处理函数分派一个唯一的ID
06. if (!handler.$$guid) handler.$$guid = addEvent.guid++;
07. //为元素的事件类型创建一个哈希表
08. if (!element.events) element.events = {};
09. //为每一个"元素/事件"对创建一个事件处理程序的哈希表
10. var handlers = element.events[type];
11. if (!handlers) {
12. handlers = element.events[type] = {};
13. //存储存在的事件处理函数(如果有)
14. if (element["on" + type]) {
15. handlers[0] = element["on" + type];
16. }
17. }
18. //将事件处理函数存入哈希表
19. handlers[handler.$$guid] = handler;
20. //指派一个全局的事件处理函数来做所有的工作
21. element["on" + type] = handleEvent;
22.};
23.//用来创建唯一的ID的计数器
24.addEvent.guid = 1;
25.function removeEvent(element, type, handler) {
26. //从哈希表中删除事件处理函数
27. if (element.events && element.events[type]) {
28. delete element.events[type][handler.$$guid];
29. }
30.};
31.function handleEvent(event) {
32. var returnValue = true;
33. //抓获事件对象(IE使用全局事件对象)
34. event = event || fixEvent(window.event);
35. //取得事件处理函数的哈希表的引用
36. var handlers = this.events[event.type];
37. //执行每一个处理函数
38. for (var i in handlers) {
39. this.$$handleEvent = handlers[i];
40. if (this.$$handleEvent(event) === false) {
41. returnValue = false;
42. }
43. }
44. return returnValue;
45.};
46.//为IE的事件对象添加一些“缺失的”函数
47.function fixEvent(event) {
48. //添加标准的W3C方法
49. event.preventDefault = fixEvent.preventDefault;
50. event.stopPropagation = fixEvent.stopPropagation;
51. return event;
52.};
53.fixEvent.preventDefault = function() {
54. this.returnValue = false;
55.};
56.fixEvent.stopPropagation = function() {
57. this.cancelBubble = true;
58.};
01.var addEvent=(function(){
02. if(document.addEventListener){
03. return function(el,type,fn){
04. if(el.length){
05. for(var i=0;i<el.length;i++){
06. addEvent(el[i],type,fn);
07. }
08. }else{
09. el.addEventListener(type,fn,false);
10. }
11. };
12. }else{
13. return function(el,type,fn){
14. if(el.length){
15. for(var i=0;i<el.length;i++){
16. addEvent(el[i],type,fn);
17. }
18. }else{
19. el.attachEvent('on'+type,function(){
20. return fn.call(el,window.event);
21. });
22. }
23. };
24. }
25.})();