jQuery - removeAttr( name ) 方法



描述

removeAttr( name ) 方法從每個匹配的元素中刪除一個屬性。

語法

以下是使用此方法的簡單語法

selector.removeAttr( name )

引數

以下是此方法使用所有引數的描述 -

  • name - 要刪除的屬性的名稱。

示例

以下示例將從每個表格中刪除邊框 -

<html>
   <head>
      <title>The Selecter Example</title>
      <script type = "text/javascript" 
         src = "https://tutorialspoint.tw/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.