日期:2014-05-16  浏览次数:20327 次

js方法(6)
if (typeof styles === "string") {
this.each(this, function (s) {
var styles = s.split(/\s+/);
var classNames = " " + this.className + " ";
for (var i = 0; i < styles.length; i++) {
classNames = classNames.replace(" " + styles[i] + " ", " ");
}
this.className = jQuery.fn.trim(classNames);
}, styles);
} else {
if (styles === undefined) {
this.each(this, function (obj) {
this.className = obj;
}, "");
}
}
return this;
}, trim:function (text) {
return (text || "").replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");
}, eq:function (index) {
if (typeof index == "number" && this.length >= index && 0 <= index) {
var e = this[index];
new Array().splice.call(this, 0, this.length);
this[0] = e;
this.length = 1;
return this;
}
}, getTagName:function (str) {
if (typeof str == "string") {
return document.getElementsByTagName(str);
}
}, css:function (key, val) {
if (typeof key == "string" && typeof val == "string") {
this.each(this, function (obj) {
this.style[obj.key] = obj.val;
}, {"key":key.replace(/-([a-z])/ig, function (f, s) {
return s.toUpperCase();
}), "val":val});
return this;
}
if (typeof key == "string" && val === undefined) {
var attrs = [];
this.each(this, function (key) {
attrs.push(this.style[key]);
}, key);
return attrs.join(",");
}
if (typeof key === "object") {
this.each(this, function (obj) {
for (var k in obj) {
this.style[k] = obj[k];
}
}, key);
return this;
}
}, attr:function (key, val) {
if (typeof key == "string" && typeof val == "string") {
this.each(this, function (obj) {
this.setAttribute(obj.key, obj.val);
}, {"key":key, "val":val});
return this;
}