- /*
- $('#test')._removeStyle('width');// ≈
- $('#test')._removeStyle('width',true);// ===
- */
- jQuery.fn.extend({
- /*移除style属性*/
- _removeStyle : function(proto,m){
- var proto = $.trim(proto.toString().toLowerCase());
- return this.each(function(){
- var CSSText = this.style.cssText;
- if( cssText ) {
- var css = cssText.split(';');
- var data = {};
- $.each( css , function(i,v){
- if( v ) {
- var d = v.split(':');
- if( d.length ) {
- data[$.trim(d[0].toLowerCase())] = $.trim(d[1]);
- }
- }
- } );
- var t = [];
- for( var k in data ) {
- if( m ) {
- if( k===proto ) continue;
- } else {
- if( k.indexOf(proto) === 0 ) continue;
- }
- t.push( k+":"+data[k]+';' );
- }
- this.style.cssText = t.join("");
- }
- });
- }
- });
- //该片段来自于http://www.codesnippet.cn/detail/2110201410720.html
来源: http://www.codesnippet.cn/detail/2110201410720.html