为什么$ .isEmptyObject($('#id-does-not-exists-on-page'))返回false?

dfa*_*ang 2 jquery

我有点困惑jQuery.isEmptyObject method.

$.isEmptyObject([]) - >返回true

$('#id-does-not-exist-on-page') => []

$.isEmptyObject($('#id-does-not-exist-on-page')) 返回false

为什么?谢谢.

Jas*_*ant 8

来自isEmptyObject,

检查对象是否为空(不包含属性)

但,

$('#id-does-not-exist-on-page') 还有房产.

$('#id-does-not-exist-on-page').addClass('abra_ka_dabra') //有效

[].addClass('abra_ka_dabra'); // TypeError:Object没有方法'addClass'

所以,

试试这个

$.isEmptyObject($('#id-does-not-exist-on-page')[0])