似乎jQuery在添加類之後進行修剪。請參見下面的jQuery addclass代碼,
addClass: function(value) {
var classNames, i, l, elem,
setClass, c, cl;
if (jQuery.isFunction(value)) {
return this.each(function(j) {
jQuery(this).addClass(value.call(this, j, this.className));
});
}
if (value && typeof value === "string") {
classNames = value.split(rspace);
for (i = 0, l = this.length; i < l; i++) {
elem = this[ i ];
if (elem.nodeType === 1) {
if (!elem.className && classNames.length === 1) {
elem.className = value;
} else {
//HERE IS APPENDS ALL CLASS IT NEEDS TO ADD
setClass = " " + elem.className + " ";
for (c = 0, cl = classNames.length; c < cl; c++) {
if (!~setClass.indexOf(" " + classNames[ c ] + " ")) {
setClass += classNames[ c ] + " ";
}
}
elem.className = jQuery.trim(setClass);
}
}
}
}
return this;
}
所以它就像下面,
jQuery.trim(" blueberry mango " + " " + "carrot")
我猜它與速度有關。這是否導致錯誤? – sissonb 2012-01-04 20:57:06
這不應該導致任何錯誤,所以它真的很重要? – 2012-01-04 21:02:06
這是一個有趣的問題。 – PeeHaa 2012-01-04 21:02:29