执行
//示例:
//$(".select").removeCss("color");
//$(".select").removeCss(["color", "border", "width"]);
(function ($) {
$.fn.removeCss = function (options) {
var type = typeof (options);
if (type === "string") {
this.each(function () {
var style = $(this).attr("style");
var arr = style.split(";");
style = "";
for (var i = 0; i < arr.length; i++) {
if ($.trim(arr[i]) == "") {
continue;
}
var att = arr[i].split(":");
if ($.trim(att[0]) == $.trim(options)) {
continue;
}
style += $.trim(arr[i]) + ";";
}
$(this).attr("style", style);
});
} else if ($.isArray(options)) {
this.each(function () {
var style = $(this).attr("style");
var arr = style.split(";");
style = "";
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < options.length; j++) {
if ($.trim(arr[i]) == "") {
break;
}
var att = arr[i].split(":");
if ($.trim(att[0]) == $.trim(options[j])) {
arr[i] = "";
continue;
}
}
}
for (var i = 0; i < arr.length; i++) {
if ($.trim(arr[i]) != "") {
style += $.trim(arr[i]) + ";";
}
}
if ($.trim(style) == "") {
$(this).removeAttr("style");
} else {
$(this).attr("style", style);
}
});
}
};
})(jQuery)