首页 > 代码库 > removeCss

removeCss

(function ($) {    //删除元素行内style中单个style和多个style    //示例:    //$(".b").removeCss("color");    //$(".b").removeCss(["color", "border", "width"]);    $.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)

 

removeCss