使用jQuery根据数据属性值查找元素非常容易。
您可以尝试运行以下代码,以学习如何使用jQuery基于数据属性值查找元素:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('[data-slide="2"]').addClass('demo');
});
</script>
<style>
.demo {
font-size: 200%;
color: green;
}
</style>
</head>
<body>
<p data-slide="1">One</p>
<p data-slide="2">Two</p>
<p data-slide="3">Three</p>
</body>
</html>