如何結合使用類選擇器和 jQuery 中的屬性選擇器?
jQuery 選擇器是一個函式,它利用表示式從 DOM 中基於給定標準查詢匹配的元素。我們可以輕鬆地結合使用類選擇器和 jQuery 中的屬性選擇器。
你可以嘗試執行以下程式碼來學習如何在 jQuery 中結合使用類選擇器和屬性選擇器−
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.myclass[reference="12345"]').css("background-color", "yellow");
});
</script>
</head>
<body>
<table>
<tr class="myclass" reference="12345">
<td>Row 1 Column 1</td>
</tr>
<tr class="myclass" reference="43215">
<td>Row 2 Column 1</td>
</tr>
<tr class="myclass" reference="54321">
<td>Row 3 Column 1</td>
</tr>
</table>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP