<html lang="en">
<head>
<meta charset="utf-8">
<title>:data() Selector 实例</title>
<link rel="stylesheet" href="https://libs.baidu.com/jqueryui/1.10.4/css/jquery-ui.min.css">
<style>
div {
width: 100px;
height: 100px;
border: 1px solid #000;
float: left;
}
</style>
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script src="https://libs.baidu.com/jqueryui/1.10.4/jquery-ui.min.js"></script>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<script>
$( "#one" ).data( "color", "blue" );
$( "#three" ).data( "color", "green" );
$( ":data(color)" ).each(function() {
var element = $( this );
element.css( "backgroundColor", element.data( "color" ) );
});
</script>
</body>
</html>