如何獲取jQuery中的屬性值?
獲取 jQuery 中的屬性值非常容易,為此,使用jQuery attr() 方法。您可以嘗試執行以下程式碼以瞭解如何在 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(){
$("button").click(function(){
alert($("img").attr("height"));
});
});
</script>
</head>
<body>
<img src="/green/images/logo.png" alt="logo" width="350" height="120"><br>
<button>Get the height</button>
</body>
</html>
廣告
資料結構
網路技術
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言
C++
C#
MongoDB
MySQL
Javascript
PHP