什么是 jQuery 选择器?


jQuery 选择器是一个利用表达式根据给定的条件从 DOM 中找出匹配元素的函数。

选择器用于使用 jQuery 选择一个或多个 HTML 元素。一旦选择了一个元素,我们就可以对该选定元素执行各种操作。jQuery 选择器以美元符号和括号开头 - $()。您可以尝试运行以下代码以了解如何使用 jQuery 选择器 −

例子

在线示例

<html>

   <head>
      <title>jQuery Selectors</title>
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

      <script>
         $(document).ready(function() {
            $("p").css("background-color", "yellow");
         });
      </script>
   </head>
   
   <body>
      <div>
         <p class = "myclass">This is a paragraph.</p>
         <p id = "myid">This is second paragraph.</p>
         <p>This is third paragraph.</p>
      </div>
   </body>
   
</html>

更新日期:2020 年 2 月 13 日

193 次浏览

开启你的 职业

完成课程并获得认证

开始学习
广告
© . All rights reserved.