如何使用带句点的 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(){
$( "div[myattr*='.']" ).css("background-color", "yellow");
});
</script>
</head>
<body>
<div id="sub1" myattr="java.subject">Java</div>
<div id="sub2" myattr=".htmlsubject">HTML</div>
<div id="sub3" myattr="rubysubject">Ruby</div>
</body>
</html>

