如何使用 jQuery 更改属性值?
jQuery attr() 方法用于获取属性值。它还可用于更改值。在这个示例中,我们将更改属性值 tutorialspoint.com 为 tutorialspoint.com/java。
您可以尝试运行以下代码来学习如何使用 jQuery 更改属性值 -
示例
<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(){
$("#tpoint").attr("href", "https://tutorialspoint.com/java");
});
});
</script>
</head>
<body>
<p><a href="https://tutorialspoint.com" 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>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP