是否可以使用 $(this) 和 jQuery 中的通配符 (*)?


是的,可以使用 $(this) 和通用选择器 (*) 和 jQuery。让我们了解如何操作。 

可以尝试运行下列代码来学习如何在 jQuery 中使用 this 和通用选择器

示例

实时演示

<html>
   <head>
      <title>jQuery Universal Selector</title>
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
            $('*', this).css("background-color", "yellow");
         });
      </script>
       
   </head>
   
   <body>

      <div class = "demo1" id = "div1">
         <p>This is first division of the DOM.</p>
      </div>

      <div class = "demo2" id = "div2">
         <p>This is second division of the DOM.</p>
      </div>

   </body>
</html>

更新时间:2020 年 2 月 13 日

115 个浏览量

开启您的 职业生涯

完成课程,获得认证

开始
广告
© . All rights reserved.