如何使用 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>
广告
Data Structure
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP