jQuery 中的 通用符 (*)函数

首页 / jQuery入门教程 / jQuery 中的 通用符 (*)函数

通用选择器选择文档中所有可用的元素。

Universal_(*) - 语法

这是使用此选择器的简单语法-

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

来源:LearnFk无涯教程网

$('*')

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

  • * -表示所有的元素。

Universal_(*) - 返回值

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

Universal_(*) - 示例

  • $('*')选择文档中所有可用的元素。

以下示例将选择所有元素,并将黄色应用于其背景。

<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() {
            /* This would select all the elements */
            $("*").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

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

技术教程推荐

Android开发高手课 -〔张绍文〕

数据分析实战45讲 -〔陈旸〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

正则表达式入门课 -〔涂伟忠〕

A/B测试从0到1 -〔张博伟〕

流程型组织15讲 -〔蒋伟良〕

Go 语言项目开发实战 -〔孔令飞〕

Web 3.0入局攻略 -〔郭大治〕

AI绘画核心技术与实战 -〔南柯〕

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