jQuery 選擇器獲取組合類中的類名
阿新 • • 發佈:2019-02-15
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文件</title>
<script type="text/javascript" src="jquery-1.10.2.js"> </script>
<script type="text/javascript">
$(function(){
$(".className2").css("background","red");
});
</script>
</head>
<body>
<div style="height:500px;width:500px">
<div class="className1 className2 " style="height:100px;width:100px;">
</div>
<div class="className2" style="height:100px;width:100px;background:green">
</div>
</div>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文件</title>
<script type="text/javascript" src="jquery-1.10.2.js"> </script>
<script type="text/javascript">
$(function(){
$(".className2").css("background","red");
});
</script>
</head>
<body>
<div style="height:500px;width:500px">
<div class="className1 className2
</div>
<div class="className2" style="height:100px;width:100px;background:green">
</div>
</div>
</body>
</html>
效果圖如下: