如何在 jQuery 中使用 attr() 方法來獲取屬性的 value?
jQuery attr() 方法用於獲取屬性的值(例如href)。將屬性作為 attr() 方法的引數提及。
你可以嘗試執行以下程式碼,瞭解如何使用 attr() 方法獲取屬性的值
示例
<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(){
alert($("#tpoint").attr("href"));
});
});
</script>
</head>
<body>
<p><a href="https://tutorialspoint.tw" id="tpoint"> Website tutorialspoint</a></p>
<button>Show complete link</button>
</body>
</html>
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP