js读取/设置元素css

Base.prototype.css = function (attr, value) {
	for (var i = 0; i < this.elements.length; i ++) {
		if (arguments.length == 1) {
				if (typeof window.getComputedStyle != 'undefined') {
				         return window.getComputedStyle(this.elements[i], null)[attr];
				} else if (typeof this.elements[i].currentStyle != 'undefined') {
				         return this.elements[i].currentStyle[attr];
				}
		} else {
		        this.elements[i].style[attr] = value;
		}
	}
	return this;
}
原文地址:https://www.cnblogs.com/fangxuele/p/5429097.html