jQuery - end() 方法



描述

end() 方法会撤销最近的破坏性操作,将匹配元素集更改回破坏性操作之前的状态。

语法

以下是使用此方法的简单语法:

operations.end( )

参数

以下是此方法使用到的所有参数的描述:

示例

以下是一个简单的示例,展示了此方法的用法。它选择所有段落,查找这些段落内的 span 元素,然后将选择恢复到段落。

<html>
   <head>
      <title>The jQuery Example</title>
      <script type = "text/javascript" 
         src = "https://tutorialspoint.com/jquery/jquery-3.6.0.js">
      </script>
		
      <script>
         $(document).ready(function(){
            $("p").find("span").end().css("border", "2px red solid");
         });
      </script>
		
      <style>
         p{ 
            margin:10px; 
            padding:10px; 
         }
      </style>
   </head>
	
   <body>
      <p><span>Hello</span>, how are you?</p>
   </body>
</html>

这将产生以下结果:

jquery-traversing.htm
广告
© . All rights reserved.