目录

remove( expr )

描述 (Description)

remove( expr )方法从DOM中删除所有匹配的元素。 这不会从jQuery对象中删除它们,允许您进一步使用匹配的元素。

将它与empty()方法进行比较。

语法 (Syntax)

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

<i>selector</i>.remove( expr )

参数 (Parameters)

以下是此方法使用的所有参数的说明 -

  • expr - 这是一个可选的jQuery表达式,用于过滤要删除的元素集。

例子 (Example)

以下是一个简单的例子,简单地显示了这种方法的用法 -

<html>
   <head>
      <title>The jQuery 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() {
            $("div").click(function () {
               $(this).remove().appendTo("#result");
            });
         });
      </script>
      <style>
         .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
      </style>
   </head>
   <body>
      <p>Click on any square below to see the result:</p>
      <p id = "result"> THIS IS TEST </p>
      <hr />
      <div class = "div" style = "background-color:blue;">ONE</div>
      <div class = "div" style = "background-color:green;">TWO</div>
      <div class = "div" style = "background-color:red;">THREE</div>
   </body>
</html>

这将产生以下结果 -

新页面打开
↑回到顶部↑
WIKI教程 @2018