(function (constructor) {
if (constructor && constructor.prototype) {
//Custom - styleMe
Object.defineProperty(constructor.prototype, 'styleMe', {
get: function () {
if (this == null) return {};
return (window.getComputedStyle ? getComputedStyle(this, null) : this.currentStyle);
},
set: function (key, newValue) {
this.styleMe.key = newValue;
}
});
}
})(window.Node || window.Element);
我可以轻松get
样式值,如:
var marginTop = document.getElementById("myID").styleMe.marginTop;
但是,如何设定价值?这不起作用:
document.getElementById("myID").styleMe.marginTop = "30px";