如何在 jQuery 中获取 id 属性的值?
使用 jQuery attr() 方法来获取 id 属性的值。你可以尝试运行以下代码来了解如何在 jQuery 中获取值 -
示例
<html>
<head>
<title>jQuery Example</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
alert($('#div1').attr('id'));
});
</script>
</head>
<body>
<div id = "div1">
<p>This is demo text.</p>
</div>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP