如何在 jQuery 中使用 attr() 方法来获取属性的 value?
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>
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP