【发布时间】:2010-07-04 01:39:34
【问题描述】:
我正在为 jQuery 编写一个插件,我想制作它,以便用户可以以任何形式将数据传递给插件。我已经解决了 JSON 或数组问题,但在尝试确定数据是否为 jQuery 对象时遇到了麻烦。
data = $('#list li');
console.debug( $.isPlainObject(data) ); // false
console.debug( $.isArray(data) ); // false
console.debug( data[0].tagName == "LI" ); // true, but see note below
最后一个方法返回true,但不能保证用户使用LI标签作为他们的数据,所以我想我需要这样的东西:
if ( $.isjQueryObject(data) ) { /* do something */ }
有人知道更好的方法吗?
【问题讨论】:
-
显然,有一个 Ben Alman 插件 - benalman.com/projects/jquery-misc-plugins/#isjquery
标签: javascript jquery object