//http://www.bigbold.com/snippets/posts/show/2630 functionaddClassName(objElement, strClass, blnMayAlreadyExist){ if ( objElement.className ){ var arrList = objElement.className.split(' '); if ( blnMayAlreadyExist ){ var strClassUpper = strClass.toUpperCase(); for ( var i = 0; i < arrList.length; i++ ){ if ( arrList[i].toUpperCase() == strClassUpper ){ arrList.splice(i, 1); i--; } } } arrList[arrList.length] = strClass; objElement.className = arrList.join(' '); } else{ objElement.className = strClass; } }
//http://www.bigbold.com/snippets/posts/show/2630 functionremoveClassName(objElement, strClass){ if ( objElement.className ){ var arrList = objElement.className.split(' '); var strClassUpper = strClass.toUpperCase(); for ( var i = 0; i < arrList.length; i++ ){ if ( arrList[i].toUpperCase() == strClassUpper ){ arrList.splice(i, 1); i--; } } objElement.className = arrList.join(' '); } }
//http://ejohn.org/projects/flexible-javascript-events/ functionaddEvent( obj, type, fn ) { if ( obj.attachEvent ) { obj["e"+type+fn] = fn; obj[type+fn] = function() { obj["e"+type+fn]( window.event ) }; obj.attachEvent( "on"+type, obj[type+fn] ); } else{ obj.addEventListener( type, fn, false ); } } //http://www.quirksmode.org/dom/getstyles.html functiongetStyle(el,styleProp) { var x = document.getElementById(el); if (x.currentStyle) var y = x.currentStyle[styleProp]; elseif (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); return y; }
//判断浏览器 var isFF=(navigator.userAgent.toLowerCase().indexOf("firefox")!=-1); var isIE=(navigator.userAgent.toLowerCase().indexOf("msie")!=-1); var isIE8=(navigator.userAgent.toLowerCase().indexOf("msie 8")!=-1);