1. 程式人生 > >jQuery :$([]).add() 在IE 下的不相容

jQuery :$([]).add() 在IE 下的不相容

系統從jq 1.4.2升級到1.7.1時發現,jquery.validate.js 在IE下無法正常工作,單步除錯進去和FF對比發現這段程式碼返回的結果不一致:

return $([]).add(this.currentForm.elements)
	.filter(":input")
	.not(":submit, :reset, :image, [disabled]")
	.not(this.settings.ignore)
	.filter(function () {
	    !this.name && validator.settings.debug && window.console && console.error("%o has no name assigned", this);
	    // select only the first element for each name, and only those with rules specified
	    if (this.name in rulesCache || !validator.objectLength($(this).rules()))
	        return false;
	    rulesCache[this.name] = true;
	    return true;
	});
IE 8 下陣列物件長度為0,而FF和chrome為8,折騰許久才發現是$([]).add()方法的問題,改成
$($.makeArray(this.currentForm.elements))...
IE和FF下就同時可用了。莫非這個是jQuery 1.7.1在IE下的不相容bug?