是否可以使用 $(this) 和通用選擇器 (*) 配合 jQuery?


是的,可以使用 $(this) 和通用選擇器 (*) 配合 jQuery。下面看看如何操作。

可以嘗試執行以下程式碼來學習如何配合 jQuery 使用 this 和通用選擇器

示例

線上演示

<html>
   <head>
      <title>jQuery Universal Selector</title>
      <script src = "https://ajax.googleapis.com/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-02-13

瀏覽次數:115

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.