是否可以使用 $(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 年 2 月 13 日

115 個瀏覽量

開啟您的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.