jQuery 中的 Name函数

首页 / jQuery入门教程 / jQuery 中的 Name函数

元素选择器选择标签名称为T的所有元素。

Name - 语法

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

$('tagname')

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

  • tagname  -  任何标准HTML标签名,如div,p,em,img,li等。

Name - 返回值

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

Name - 示例

  • $('p')     -  选择文档中标签名称为 p 的所有元素。

  • $('div')  -  选择文档中标签名称为 div 的所有元素。

以下示例将选择所有划分,并将黄色应用于其背景-

<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 divisions */
            $("div").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

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

技术教程推荐

深入拆解Java虚拟机 -〔郑雨迪〕

OpenResty从入门到实战 -〔温铭〕

后端技术面试 38 讲 -〔李智慧〕

人人都能学会的编程入门课 -〔胡光〕

Service Mesh实战 -〔马若飞〕

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

Kubernetes入门实战课 -〔罗剑锋〕

手把手教你落地DDD -〔钟敬〕

LangChain 实战课 -〔黄佳〕

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