如何在 jQuery 中根据数据属性值查找元素?
jqueryweb developmentfront end technology
使用 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() {
$('[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>

