如何使用 jQuery 從每個標籤中移除一個屬性?
要使用 jQuery 從每個標籤中移除一個屬性,請使用 removeAttr() 方法。你可以嘗試執行以下程式碼來學習如何移除屬性 −
例項
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1").removeAttr("style");
});
});
</script>
</head>
<body>
<h1 style="color:blue">This is heading</h1>
<p>This is demo text.</p>
<h1 style="color:red">This is heading</h1>
<p>This is demo text.</p>
<button>Remove</button>
<p>Click above to remove style attribute from all h1 elements.</p>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP