jQuery 中的 多元素E, F, G函数

首页 / jQuery入门教程 / jQuery 中的 多元素E, F, G函数

这个多元素选择器选择所有指定选择器E,F或G的组合结果。

您可以指定任意数量的选项以组合成一个输出。这里,jQuery对象中DOM元素的顺序不一定相同。

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/selector-multiple-elements.html

来源:LearnFk无涯教程网

Multiple_Elements_E,_F,_G - 语法

$('E, F, G,....')

这是此选择器使用的所有参数的描述-

  • E   -  任何有效的选择器

  • F   -  任何有效的选择器

  • G   -  任何有效的选择器

  • ....

Multiple_Elements_E,_F,_G - 返回值

像任何其他jQueryselector一样,该选择器还返回一个填充有找到的元素的数组。

Multiple_Elements_E,_F,_G - 示例

  • $('div,p')-匹配 div 或 p 匹配的所有元素。

  • $('p strong,.myclass')-匹配<p><strong>LearnFK</strong></p>或 class='myclass'的元素。

  • $('p strong,#myid')-匹配<p><strong>LearnFK</strong></p>或 id='myid'的元素。

以下示例将选择ID为 big 的元素和ID为 div3 的元素,并将黄色应用于其背景-

<html>
   <head>
      <title>The Selecter Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            $(".big, #div3").css("background-color", "yellow");
         });
      </script>
   </head>
	
   <body>
      <div class="big" id="div1">
         <p>This is first division of the DOM.</p>
      </div>

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

      <div class="small" id="div3">
         <p>This is third division of the DOM</p>
      </div>
   </body>
</html>

这将产生以下输出-

This is first division of the DOM.

This is second division of the DOM.

This is third division of the DOM

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

机器学习40讲 -〔王天一〕

Electron开发实战 -〔邓耀龙〕

Serverless入门课 -〔蒲松洋(秦粤)〕

分布式系统案例课 -〔杨波〕

体验设计案例课 -〔炒炒〕

打造爆款短视频 -〔周维〕

如何讲好一堂课 -〔薛雨〕

玩转Vue 3全家桶 -〔大圣〕

eBPF核心技术与实战 -〔倪朋飞〕

好记忆不如烂笔头。留下您的足迹吧 :)