removeProperty与removeAttribute的区别应用

简单地讲:removePropertyremoveAttribute区别是:

 

  • 符合w3c的(gecko,opera,webkit)的使用removeProperty
  • IE的使用removeAttribute
/*
*isString-judge the source is or not string*
*@function*
*@param source*
*@return {boolean}*
*/
ZYC.lang.isString = function(source){
    return Object.prototype.toString.call(source) === "[object String]";
};
 
 
/*
*_getId*
*@inner-function*
*@param id*
*@relay on ZYC.lang*
*/
ZYC.dom._getId = function(id){
    if(ZYC.lang.isString(id)){
	   return document.getElementById(id);
     }
	 return id;
}



/*
*removeStyle delete some style*
*@function*
*@param {HTMLElement|String} el*
*@param {String} st*
*@return {HTMLElement} el*
*/
ZYC.dom.removeStyle = function(){
    var ele = document.createElement('DIV'),
	    fn,
		_g = ZYC.dom._getId;
		
	if(ele.style.removeProperty){
	   fn = function(el,st){
	      el = _g(el);
		  el.style.removeProperty(st);
		  return el;
	   };
	}else if(ele.style.removeAttribute){
	   fn = function(el,st){
	      el = _g(el);
		  el.style.removeAttribute(ZYC.string.toCamelCase(st));
		  return el;
	   };
	}
    ele = null;   //这种习惯要有
    return fn;	
}();


 

你可能感兴趣的:(js,dom,removeAttribute,removeProperty)