jQuery - removeAttr( name ) 方法



描述

removeAttr( name ) 方法从每个匹配的元素中删除一个属性。

语法

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

selector.removeAttr( name )

参数

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

  • name - 要删除的属性的名称。

示例

以下示例将从每个表格中删除边框 -

<html>
   <head>
      <title>The Selecter Example</title>
      <script type = "text/javascript" 
         src = "https://tutorialspoint.com/jquery/jquery-3.6.0.js">
      </script>
   
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("table").removeAttr("border");
         });
      </script>
   </head>
	
   <body>
      <table border = "2">
         <tr><td>This is first table</td></tr>
      </table>

      <table border = "3">
         <tr><td>This is second table</td></tr>
      </table>

      <table border = "4">
         <tr><td>This is third table</td></tr>
      </table>	
   </body>
</html>

这将产生以下结果 -

jquery-attributes.htm
广告

© . All rights reserved.