为什么$ .isEmptyObject($('#id-does-not-exist-on-on-page-)不返回? [英] why $.isEmptyObject($('#id-does-not-exist-on-page')) returns false?

查看:71
本文介绍了为什么$ .isEmptyObject($('#id-does-not-exist-on-on-page-)不返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对jQuery.isEmptyObject method有点困惑.

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

但是

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

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

为什么? 谢谢.

推荐答案

来自 isEmptyObject

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

Check to see if an object is empty (contains no properties)

但是

$('#id-does-not-exist-on-page')仍然具有属性.

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

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

[].addClass('abra_ka_dabra'); // TypeError: Object has no method 'addClass'

所以

改为尝试

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

这篇关于为什么$ .isEmptyObject($('#id-does-not-exist-on-on-page-)不返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆