1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| <!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>
|