<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div{
background-color: red;
}
</style>
</head>
<body>
<div id="one">id选择器</div>
<div class="c1">c1选择器--div</div>
<div class="c1">c1选择器--div</div>
<p class="c1">c1选择器--p标签</p>
<ul class="box">
<li>列表1</li>
<li>列表2</li>
<li>列表3</li>
<li>列表4</li>
<li>列表5</li>
<li>列表6</li>
</ul>
</body>
</html>
<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
console.log($("#one"));
console.log($(".box li"));
console.log($(".box li:first-child"));
console.log($(".c1"));
var one = document.querySelector("#one");
one.style.backgroundColor = "palevioletred";
$(".box li:first-child").css("background-color", "#6A5ACD");
var liArray = document.querySelectorAll(".box li");
for(var i = 0; i < liArray.length; i++){
liArray[i].style.backgroundColor = "yellowgreen";
}
$(".c1").css("background-color", "deepskyblue");
$(".c1").css({
width:'300px',
height:"100px"
});
function randomColor(){
var red = Math.floor(Math.random() * 256);
var green = Math.floor(Math.random() * 256);
var blue = Math.floor(Math.random() * 256);
return "rgb(" + red + "," + green + "," + blue + ")";
}
$(".c1").css("background-color", function(index, value){
return randomColor();
})
$(".c1").css("height", function(index, value){
return (index + 1) * 100;
})
$(".c1").css("width", function(index, value){
return Math.floor(Math.random() * 301 + 100);
})
</script>
