.class选择器在jQuery中用于选择多个类。
语法如下:
$(".class1, .class2, .class3, ...")
参数:
- 类:需要此参数来指定要选择的元素的类别。
示例1:
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" >
</ script >
< script >
$(document).ready(function() {
$(".geeks, .for, .lsbin").css(
"background-color", "green");
});
</ script >
</ head >
< body >
< center >
< h1 class = "geeks" >
Welcome to lsbin
</ h1 >
< p >Geeks1</ p >
< p class = "for" >Geeks2</ p >
< p >Geeks3</ p >
< p class = "lsbin" >
Geeks3
</ p >
</ center >
</ body >
</ html >
输出如下:
示例2:
<!DOCTYPE html>
< html >
< head >
< script src =
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" >
</ script >
< script >
$(document).ready(function() {
$(".c1, .c2").css(
"background-color", "green");
});
</ script >
</ head >
< body >
< center >
< h1 class = "geeks" >
Welcome to lsbin
</ h1 >
< p class = "c1" >Geeks1</ p >
< p class = "for" >Geeks2</ p >
< p class = "c2" >Geeks3</ p >
< p class =
"lsbin" >
Geeks3
</ p >
</ center >
</ body >
</ html >
输出如下: