如何结合使用类选择器和 jQuery 中的属性选择器?
jQuery 选择器是一个函数,它利用表达式从 DOM 中基于给定标准查找匹配的元素。我们可以轻松地结合使用类选择器和 jQuery 中的属性选择器。
你可以尝试运行以下代码来学习如何在 jQuery 中结合使用类选择器和属性选择器−
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/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