如何在 jQuery 中獲取 id 屬性的值?
使用 jQuery 的 attr() 方法來獲取 id 屬性的值。你可以嘗試執行以下程式碼來了解如何在 jQuery 中獲取值 -
示例
<html>
<head>
<title>jQuery Example</title>
<script src = "https://ajax.googleapis.com/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>
廣告
資料結構
計算機網路
關係型資料庫管理系統(RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP