如何使用 jQuery 的 attr() 方法獲取屬性值?
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>
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP