jquery选择方法

时间:2013-02-04 10:48:13

标签: javascript jquery

   <script>
            $("*", document.body).each(function () {//is document.body a context?
                var parentTag = $(this).parent().get(0).tagName;
                //Above statement is only selecting the body tag why?

                $(this).prepend(document.createTextNode(parentTag + " > "));
            });
    </script>
  </body>
</html>       

在上面的脚本中是否有任何理由只选择body标签?document.body也是一个上下文?因为document.body没有被引用它是一个上下文吗?

1 个答案:

答案 0 :(得分:1)

我希望这些是您正在寻找的激光器

> Is there any reason for selecting only body tag in the above script?

它不会仅选择Bodytag,如果您在Chrome中运行此代码,则会看到标记

 $("*" ,document.body).each(function (idx, elem) {
 console.log(elem);
 });
  

document.body也是一个上下文吗?

是的,这是API LINK

的一行
  

因为没有引用document.body会是一个上下文吗?

是的,这是API LINK

的一行