如何使用 jQuery 更改屬性值?
jQuery attr() 方法用於獲取屬性值。它還可用於更改值。在這個示例中,我們將更改屬性值 tutorialspoint.com 為 tutorialspoint.com/java。
您可以嘗試執行以下程式碼來學習如何使用 jQuery 更改屬性值 -
示例
<html>
<head>
<title>Selector Example</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#tpoint").attr("href", "https://tutorialspoint.tw/java");
});
});
</script>
</head>
<body>
<p><a href="https://tutorialspoint.tw" id="tpoint">tutorialspoint.com</a></p>
<button>Change attribute value</button>
<p>The value of above link will change on clicking the above button. Check before and after clicking the link.</p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP