如何使用 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>
廣告
Data Structure
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP