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
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <img src=""/> <img src=""/> <img src=""/> <a href="">百度</a> <div id="one"></div> <input type="checkbox" /> </body> </html> <script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"> var img = document.querySelector("img"); img.src = "img/t1.png"; img.type = "天猫图片"; console.log(img.type); img.setAttribute("src", "img/t1.png"); img.setAttribute("index", "第一张"); console.log(img.getAttribute("index"));
$("a").attr("href", "http://www.baidu.com"); $("img").attr({ src:"img/t2.jpg", width:300 }); console.log($("a").attr("href")); console.log($("img").attr("src")); $("img").removeAttr("width"); $("a").removeAttr("href"); var imgNameArray = []; $("img").attr("src", function(index, value){ return "img/t" + (index + 2) + ".jpg"; }) $("img").attr("width", function(index, value){ return 520 - (index + 1) * 100 }) $("a").prop("href", "http://baidu.com"); $("div").prop({ num:1, data:"自定义一个属性值" });
console.log($("div").prop("num")); console.log($("img").prop("src")); $("a").removeProp("href");
console.log($("input").prop("checked")); console.log($("input").attr("checked")); </script>
|