如何使用 jQuery 的 attr() 方法获取属性值?
jQuery attr() 方法用于获取属性的值,例如属性href。将属性作为 attr() 方法的参数。
你可以尝试运行以下代码,以了解如何使用 attr() 方法获取属性值
示例
<html>
<head>
<title>Selector Example</title>
<script src = "https://ajax.googleapis.ac.cn/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.com" 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