javascript – 检查jquery对象内容

有谁知道,为什么 jquery的行为如下:

var $test = $(window).add(document).add("body");
$test.is(window) -> false
$test.is(document) -> true
$test.is("body") -> true

如何通过“is”查明jquery-object是否包含窗口?

解决方法

var $test = $(window).add(document).add("body");
$test.is(function(index,elements) {
    return this === window;
});

jQuery“is()”方法检查传递的元素的nodeType. Document的nodeType为9. Body的nodeType为1. Window没有nodeType,ergo“undefined”,其值为false.要解决这个问题,请构建您自己的过滤功能,如上所示.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...