如何刪除使用prop()方法新增的屬性

admin發表於2017-04-07

大家知道使用prop()方法可以為指定的元素新增屬性。那麼如何刪除使用prop()方法新增的屬性呢,下面就通過程式碼例項做一下介紹。程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("td").prop({width:"200",height:"300"});
  $("button").click(function(){
    $("td").removeProp("width");
  })
})
</script>
</head>
<body>
<table border="1">
  <tr>
    <td>歡迎來到螞蟻部落</td>
  </tr>
</table>
<button>刪除屬性</button>
</body>
</html>

使用removeProp()方法即可實現我們的要求。

具體可以參閱jQuery removeProp()一章節。

相關文章